php - How to passing two id's from the URL to the controller in laravel

273

I'm sorry I can't pass two ids from the URL to the controller give me an error Undefined variable: id

the problem in the user id in the controller

My Route:

Route::get('addappotouser/{id}/{dates_id}','[email protected]');

Href :

<a href="{{url('addappotouser' . '/'. $usersss->id .'/'. $date->id)}}" value="" class="btn btn-success btn-mini deleteRecord" type="submit">{{$date->Dates}}</a>

Controller:

 public function create( $id , $dates_id)
{
      $bookappoitm=DB::table('times')


          ->where('times.Dates_id',$dates_id)

       //  ->where('times.Dates_id',1)


         ->whereNoTIn('times.id',function($query){

           $query->select('times_id')->from('bookappoitments')
          ->where('users_id',$id) 

         ->get();

     })


   ->get();


   $datee=Dates::find($dates_id)
   ->where('dates.id',$dates_id)
    ->select('dates.*')
    ->first();


    $userss=User::find($id)
    ->where('id',$id)
    ->select('users.*')
    ->first();

     return view('admin.Managers.addappotouser', compact('bookappoitm','datee','userss'));

URL:

http://127.0.0.1:8000/addappotouser/1/1
792

Answer

Solution:

Update your code with this you need to use$id like this

$bookappoitm=DB::table('times')->where('times.Dates_id',$dates_id)->whereNoTIn('times.id',function($query) use ($id){

       $query->select('times_id')->from('bookappoitments')
        ->where('users_id',$id) 
        ->get();
     })
     ->get();
38

Answer

Solution:

You need pass the parameters as array, see https://laravel.com/docs/5.6/helpers#method-route,

<a href="{{url('addappotouser', [$usersss->id, $date->id])}}" value="" class="btn btn-success btn-mini deleteRecord" type="submit">{{$date->Dates}}</a>
968

Answer

Solution:

Change the line as below:

->whereNoTIn('times.id',function($query) use ($id){

People are also looking for solutions to the problem: php - jQuery live calc multirow input

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.