31

In my application, a user has the ability to remind another user about an event invitation. To do that, I need to pass both the IDs of the event, and of the user to be invited.

In my route file, I have:

Route::get('events/{id}/remind', [
'as' => 'remindHelper', 'uses' => 'EventsController@remindHelper']);

In my view, I have:

{!!link_to_route('remindHelper', 'Remind User', $parameters = array($eventid = $event->id, $userid = $invitee->id) )!!}

In my controller, I have:

    public function remindHelper($eventid, $userid)
{
    $event = Events::findOrFail($eventid);
    $user = User::findOrFail($userid);
    $invitees = $this->user->friendsOfMine;
    $invited = $event->helpers;
    $groups = $this->user->groupOwner()->get();
    return view('events.invite_groups', compact('event', 'invitees', 'invited', 'groups'));
}

However, when I hit that route, I receive the following error:

Missing argument 2 for App\Http\Controllers\EventsController::remindHelper()

I'm sure I have a formatting error in my view, but I've been unable to diagnose it. Is there a more efficient way to pass multiple arguments to a controller?

2
  • 1
    Can you show us your route definition? Jul 28, 2015 at 16:11
  • Sure, I updated the original question. Jul 28, 2015 at 16:13

6 Answers 6

79

When you define this route:

Route::get('events/{id}/remind', [
'as' => 'remindHelper', 'uses' => 'EventsController@remindHelper']);

You are saying that a single URI argument will be passed to the method.

Try passing the two arguments, like:

Route::get('events/{event}/remind/{user}', [
'as' => 'remindHelper', 'uses' => 'EventsController@remindHelper']);

View:

route('remindHelper',['event'=>$eventId,'user'=>$userId]);
1
  • how can we pass multiple optional parameters and use them?
    – Kamlesh
    May 6, 2021 at 6:39
5

Route :

Route::get('warden/building/{buildingId}/employee/{employeeId}',[
    'uses'=>'WardenController@deleteWarden',
    'as'=>'delete-warden'
]);

View :

<a href="{{route('delete-warden',[$building->id])}}"></a>

Controller:

public function deleteWarden($buildingId,$employeeId){
    $building = Building::find($buildingId);
    $building->employees()->detach($employeeId);
    return redirect('warden/assign/'.$buildingId)->with('message','Warden Detached successfully');

}
1
  • Dear brother, how is it possible? You declare route as delete-warden and call route as delete-building
    – A.A Noman
    Aug 7, 2021 at 5:37
1
Route::get('/details/{id}/{id1}/{id2}', 'HomeController@SearchDetails');

//pass data like the below code

<a href="{{url("/details/{$orga_list->dcode}/{$orga_list->dname}/{$GroupHead}")}}" 
target="_blank" > Details </a>

//controller write like the below code

public function SearchDetails($id, $searchtext,$grp_searchtext)  
{
// get data like the below code

$data['searchtext'] = $searchtext;
$data['grp_searchtext'] = $grp_searchtext;
$data['id_is'] = $id;
}
1

This is how you do it:

<a href="{{route('route.name',['param1'=>$variable1,'param2'=>$variable2])}}">Click Here</a>
0

Go to your controller and write code like following:

public function passData()
{

    $comboCoder=['Bappy','Sanjid','Rana','Tuhin'];
    $ffi=['Faisal','Sanjid','Babul','Quiyum','Tusar','Fahim'];
    $classRoom=['Sanjid','Tamanna','Liza'];
    return view('hyper.passData',compact('comboCoder','ffi','classRoom'));
}

/*
Again, in View part use:
(passData.blade.php)
*/

<u>Combocoder:</u>

@foreach($comboCoder as $c)
{{$c}}<br>
@endforeach

<u>FFI</u>

@foreach($ffi as $f)

{{$f}}<br>
@endforeach

<u>Class Room </u>

@foreach($classRoom as $cr)

{{$cr}}<br>
@endforeach
0

routes/web.php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BookController;

Route::controller(BookController::class)->group(function () {
     Route::get('author/{author_name}/book/{title}', 'show')
      ->name('book.show');
 });

Now update the controller like:

app/Http/Controllers/BookController.php

namespace App\Http\Controllers;

use App\Models\Book;
use App\Models\Author;
use Illuminate\Http\Request;

class BookController extends Controller
{

  public function show(Request $request, Author $author, Book $book)
  {   
    return view('show',[
        'book' => $book->show($request)
    ]);
  }
}

Now update the book model:

app\Models\Book.php

namespace App\Models;

use App\Common\HasPdf;
use App\Common\HasImage;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Support\Facades\URL;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Book extends Model
{
  use HasFactory;

  protected $guarded = [];

  public function author() : BelongsTo
  {
     return $this->belongsTo(Author::class);
  }


  public function url()
  {
    return URL::route('book.show', [
        'author_name' => $this->author->author_name,
        'title'   => $this->title,
    ]);
  }
}

<a href="{{ $item->url() }}"><h3>{{ $item->title }}</h3></a>

Hope it can help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.