Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1020 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing multiple parameters to controller in Laravel 5

#1
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?
Reply

#2
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]);

Reply

#3
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

Reply

#4
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;
}
Reply

#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');

}
Reply

#6
This is how you do it:

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

#7
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.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through