I
I
ilya173922019-08-22 17:26:34
Laravel
ilya17392, 2019-08-22 17:26:34

Undefined variable: user_id, what's the problem?

@if(Auth::user()->id == $user_id)
       
      <form method="POST" action="">
                            <button class="btn btn-danger">Delete</button>
                            @csrf
                            @method('DELETE')
        </form>
   
   @endif

gives an error: Undefined variable: user_id (View: C:\OpenServer\OSPanel\domains\project\resources\views\edit.blade.php)
registered in the controller
public function showUserAd($user)
    {
        $user = User::where('username', $user)->first();
        
        if(empty($user)){
            abort(404);
        }
      
        return redirect()->route('adShow', [$oneAd]);
    }

route migration table users
Route::get('/{id}', '[email protected]');
Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username')->unique();
            $table->string('password');
            
            $table->timestamps();
        });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
organica, 2019-08-22
@ilya17392

You do not pass the $user_Id variable from the controller to the template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question