I have a RESTful controller, that I'm trying to get my ajax to get to, and I keep getting an internal sever error 500, controller method not found.
In the routes.php I have:
Route::controller('friends', 'FriendController');
In the controller I have:
class FriendController extends Controller{
public function postAdd(){
$user_id = Auth::user()->id;
$friend_id = Input::get('id');
$friend = new Friend;
$friend->user_id = $user_id;
$friend->friend_id = $friend_id;
if($friend->save()){
return Response::json(array('status' => 'OK'));
}else{
return Response::json(array('status' => 'FAIL'));
}
}
}
and the ajax is:
$.ajax({
url : "{{URL::action('FriendController@postAdd')}}",
type : "POST",
data : { id : $(this).attr('val')}
})
.done(function(json){
console.log(json);
});
resulting in http://localhost/velser/friends/Add
for the URL.
Any idea where I'm going wrong? And if you see any other relevant problems with the code, let me know please! I'm still getting used to laravel 4, so I still have many issues I believe.
EDIT: Includin the Friend model now too:
class Friend extends Eloquent{
protected $table = 'friends';
}