I started learning laravel a week ago, and I am still confused by how to update data and my english is not good
I have two tables and I want to update two data on different tables at a time, what can i do, can someone tell me?
users table
- id --> "1"
- type_id --> "3"
- name --> "john"
- email --> "[email protected]"
- password --> "123"
channels table
- id --> "1"
- user_id --> "null"
- name --> "channel #1"
*type_id --> 1 = admin, 2 = dj, 3 = user
this is what i need
if the user clicks on the "take channel" button, I want to update the type_id in the users table from "3" to "2", which means the user has changed to a dj, and also fill user_id in the channel table with the id of the user who clicked the button, can anyone tell me how?
I'm not sure of my code, but here's the code that comes to my mind
UserController.php
public function becomeDJ()
{
$channel = App\Channel::find('id');
$channel->user_id = Auth::user()->id;
$channel->save();
$user = App\User::find('type_id');
$user->type_id = '2';
$user->save();
return view('dashboard.editChannel');
}
becomeDJ.blade.php
@foreach ($channels as $channel)
<div class="col s12 m4 l3">
<div class="card grey lighten-4">
<div class="card-content p-3">
<h5 class="truncate mt-0 mb-0">{{ $channel->name }}</h5>
<div class="d-flex justify-content-between">
<div>
<p>DJ : Username</p>
<small>ID Channel : {{ $channel->id }}</small>
</div>
<a href="/become-dj/{{ $channel->id }}/process" class="btn-flat"><i class="material-icons">flag</i></a>
</div>
</div>
</div>
</div>
@endforeach
routes/web.php
Route::get('/become-dj/{channel}/process', 'UserController@becomeDJ');