mercredi 29 juillet 2020

How to display database table data on a view for a specific authenticated user

I'm currently working on a feature where when a user is created his job position can be selected and I connected that through a foreign key where the user gets to select the ID of the specific job and it works well when storing the data, the actual ID of the specific field is showing on the users table but now my problem is when I want to show that specific data of the authenticated user Here's the table I have

Job's Table

  1. id
  2. job_name
  3. line_manager
  4. department
  5. branch
  6. job_type

The id is a foreign key for the users table at

  1. job_id

Heres my JobController:

public function index()
    {
        $role = Auth::guard('web')->user()->role_id;
        if($role == 1)
        {
            $jobs = Job::latest()->where('id',auth()->user()->id)->get();
            return view('job.index',compact('jobs'));
        }

The Model:

class Job extends Model
{
    protected $table = 'jobs';

    public function jobWhich()
    {
        return $this->job_name;
    }

And this is the view I want the data of that ID that I selected when I created the user to show here(its static data that was inserted in the database so it won't change)

<tbody>
@foreach($jobs as $job)
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
@endforeach
</tbody>

I'm not sure if I need to show the users controller on how I store this into the user but it's working well because I can see the id of the specific field at the user when I create



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2P222zA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire