@paduraruionutandrei have you looked at Laravel Passport for APIs, unsure as to your requirements but purpose-built for APIs e.g. tokens, etc. https://laravel.com/docs/6.x/passport I assume you mean an API that can be consumed by other applications? Relations are data structures and have little to do with auth or access. If you are looking to share data with functionality outside of your own app then API like passport would work.
Code review
Hello everyone, this is a question is not for solving problems purpose, but to see if I am on the right way.I'm building an API for my first web app(I am a beginner) and try to write clean code(always find ways to improve my code, but doing my best).I have 4 models and their migrations for now, Company, Project, Bucket, Task.Everything in my app will be tied up to company, but I cannot figure it out If I do the right thing here.So here is my idea.I tied up Projects to company(one to many relationship), and then tied up Bucket to Project(one to many relationship again) and then Tasks to Buckets(again, one to many).
/**
* Company projects
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function projects()
{
return $this->hasMany('App\Models\Project', 'company_id', 'id');
}
/**
* project->buckets
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function buckets()
{
return $this->hasMany('App\Models\Bucket', 'project_id', 'id');
}
/**
* bucket->tasks
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function tasks()
{
return $this->hasMany('App\Models\Task', 'bucket_id', 'id');
}
Now my doubt is: When I add a middleware(like I said everything will be tied up to Company), for authorization purpose, another user will be able to access for example (/projects/1/bucket/1/tasks/1).And if it is a good way to do this, I mean I made something like a "stair".I tied up projects to companies, and then buckets to projects, and then tasks to buckets.
Sorry, If you do not understand my question.I am still a beginner and try to improve myself everyday!Thanks in advice!
Please or to participate in this conversation.