title: Laravel Update user's data
body: <p>I'm building a traveling app and the user has the possibility to edit their own departure date in case of a misplacement. At the moment, the user can edit the departure date from everyone. While it only should edit their own. Everything is working, but the update function where it should look for <code>Auth::user();</code>. Any idea how I should make this? </p>
  
  <p>Here is the code:- </p>
  
  <p><code>DepartureController.php</code></p>
  
  <pre><code> public function edit(LocationUser $LocationUsers)
  {
      return view('departure.edit', compact('LocationUsers'));
  }
  
  public function update(Request $request, LocationUser)
  {
      $LocationUsers = Auth::user();
  
      $LocationUsers-&gt;update($request-&gt;all());
  
      return redirect()-&gt;route('home', $LocationUsers)
          -&gt;withSuccess('Departure updated!');
  }
  </code></pre>
  
  <p>The <code>web.php</code></p>
  
  <pre><code>//Backend Departure date
  Route::get('/departure/create', 'DepartureController@create')-&gt;name('departure.create');
  Route::post('/departure/create', 'DepartureController@store')-&gt;name('departure.store');
  Route::get('/departure/edit/{LocationUsers}', 'DepartureController@edit')-&gt;name('departure.edit{id}');
  Route::patch('/departure/edit/{LocationUsers}', 'DepartureController@update')-&gt;name('departure.update');
  </code></pre>
  
  <p>The <code>edit.blade.php</code></p>
  
  <pre><code>&lt;div class="container-fluid"&gt;
      &lt;div class="row justify-content-center"&gt;
          &lt;div class="col-md-8"&gt;
              &lt;div class="card card-default"&gt;
                  &lt;div class="card-header"&gt;
                      {{$LocationUsers-&gt;departure_date}}
                      Update my departure
                  &lt;/div&gt;
                  &lt;div class="card-body"&gt;
                      @if (session('success'))
                          &lt;div class="alert alert-dismissible alert-success"&gt;
                              {{ session('success') }}
                              &lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;
                                  &lt;span aria-hidden="true"&gt;×&lt;/span&gt;
                              &lt;/button&gt;
                          &lt;/div&gt;
                      @endif
                      @if ($errors-&gt;any())
                          &lt;div class="alert alert-danger"&gt;
                              &lt;ul&gt;
                                  @foreach ($errors-&gt;all() as $error)
                                      &lt;li&gt;{{ $error }}&lt;/li&gt;
                                  @endforeach
                              &lt;/ul&gt;
                          &lt;/div&gt;
                      @endif
                          &lt;form method="post" action="{{route('departure.update', $LocationUsers)}}"&gt;
                              {!!csrf_field().method_field('patch')!!}
                          &lt;div class="form-group"&gt; &lt;!-- Date input --&gt;
                              &lt;label class="control-label" for="departure_date"&gt;&lt;/label&gt;
                              Date
                              &lt;input class="form-control" id="departure_date" name="departure_date"
                                     placeholder="DD/MM/YYYY" type="text"/&gt;
                          &lt;/div&gt;
                          &lt;input type="submit" class="btn btn-primary" value="Update departure"&gt;
                          &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The <code>User model</code></p>
  
  <pre><code>public function daysUntilDeparture()
  {
      if ($this-&gt;location()-&gt;count() &lt; 1) {
          return "No departure date has been given";
      }
  
      $location = $this-&gt;location[0];
  
      $userLocation = LocationUser::where('user_id', $this-&gt;id)
          -&gt;where('location_id', $location-&gt;id)
          -&gt;first();
  
      $departure_date = $userLocation-&gt;departure_date;
      return $departure_date-&gt;diffInDays(Carbon::now());
  
  
  }
  </code></pre>
  
  <p>The <code>LocationUser</code> model</p>
  
  <pre><code>&lt;?php
  </code></pre>
  
  <p>namespace App;</p>
  
  <p>use Carbon\Carbon;
  use Illuminate\Database\Eloquent\Model;</p>
  
  <p>class LocationUser extends Model
  {
      const DATE_FORMAT = 'd-m-Y';</p>
  
  <pre><code>protected $fillable = ['departure_date', 'user_id'];
  protected $dates = ['departure_date'];
  protected $table = 'location_users';
  
  public function user() {
      return $this-&gt;belongsTo('\App\User', 'id', 'user_id');
  }
  
  public function location() {
      return $this-&gt;hasOne('\App\Location', 'id', 'location_id');
  }
  
  public function setDepartureDateAttribute($date)
  {
      $this-&gt;attributes['departure_date'] = Carbon::createFromFormat(self::DATE_FORMAT, $date);
  }
  </code></pre>
  
  <p>}</p>