I have updated my view for displaying data - projects, with angularjs and now i have problem that when i change in URL address id of project, method show() didn't show 404 error - project does not belongs to logged in user, instead i'm getting this error.
Trying to get property of non-object (View: C:\www\htdocs\laravel\resources\views\backend\partials\project\single-project.blade.php)
Before i've updated my view to work with angularjs everything was working fine.
My angular controller:
freelo.controller('mainCtrl', ['$scope', '$http', function($scope, $http) {
$scope.projects = [];
$http.get('api/userProjects')
.then(function(response) {
$scope.projects = response.data;
});
}]);
My app.js:
var freelo = angular.module('freelo', []);
Method for retrieving user projects:
public function getProjectsInJson(){
$project = Project::where('user_id', '=', $this->getCurrentUserId())->get();
return response()->json($project);
}
And my show() method in ProjectsController:
public function show($id){
$project = Project::where('id', $id)
->where('user_id', '=', $this->getCurrentUserId())
->first();
$user = DB::table('projects')
->join('users', 'projects.user_id', '=', 'users.id')
->join('profiles', 'users.id', '=', 'profiles.user_id')
->select('users.id','profiles.username')
->where('projects.id','=', $id)
->get();
if(!$project && !$user){
abort(404);
}else{
return view('backend.partials.project.single-project')->with('project', $project)->with('user', $user);
}
}
Where did i make mistake or what must be changed?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire