Ad

Function Create With Show Project Details By Id In Laravel

- 1 answer

Controller:

    public function create(Request $id)
{
    $data = OperationalPlan::findOrFail($id);
    $val = explode("|-|",$data->text);
    $nval = explode("|-|",$data->ntext);
    $neval = explode("|-|",$data->netext);
    $newval = explode("|-|",$data->newtext);
    $mnue1 = StrategicGoal::get();
    $mnue2 = Measurement::get();
    $mnue3 = tawagh::get();
    $mnue4 = detailed_target::get();
    $mnue5 = Management::get();
    $mnue6 = Department::get();
    $mnue7 = activety::where([['department', Auth::user()->department],['is_confirmed', 1],['is_deleted',0],])->get();


    return view('user.report.create' . $id , compact('mnue1', 'mnue2','mnue3', 'mnue4', 'mnue5', 'mnue6','mnue7',
    'val', 'nval', 'neval', 'newval', 'data'));
}

route:

  Route::get('/report/create/{id}','User\[email protected]')->name('dashboard.report.create.id');

url :

<a target="_blank" rel="nofollow noreferrer" href="{{ route('report.create', $project->id) }}" class="" title="View">

the message error is :

Property [text] does not exist on this collection instance.

can some one helps me please i tried to fix this but i do not got it.

Ad

Answer

Sure, remove the type-hint on $id. The 'id' being passed is NOT a Request:

public function create($id)

When you type-hinted that as Request, $id ends up being a Request object. When you pass that to findOrFail which will call find which will then call findMany, it will end up converting the Request to an array with toArray() since Request is Arrayable. This will end up returning a Collection because it thinks you are trying to find many records not a single record.

In short with what you had you ended up passing the array of inputs to find, not the 'id' you are looking for.

Ad
source: stackoverflow.com
Ad