PHP Laravel - routing - Object of class stdClass could not be converted to string

PHP Laravel - routing - Object of class stdClass could not be converted to string

Hi,

groping when creating the correct route in the Laravel framework, resp. I don't know how to properly pass an instance of an object in a route - how to pass it for GET. Specifically, I have in one file show.blade.php a link to edit via link route ('item.edit', ['item' => $ item]) .




I created it like this:

ERROR
-------------------------------------------------- -
Facade \ Ignition \ Exceptions \ ViewException
Object of class stdClass could not be converted to string (View: /var/www/laravel/dev1/resources/views/item/analyzer.blade.php)


route web.php
-------------------------------------------------- -

Route :: get ('/ item / analyzer / {item_id} / {upload_id}', function ($ item_id, $ upload_id) {
$ item = DB :: table ('items') -> where ('id', $ item_id) -> first ();
$ upload = DB :: table ('uploads') -> where ('id', $ upload_id) -> first ();
$ t = new App \ Http \ Controllers \ itemController;
return view ('item.analyzer', ['results' => $ t-> handleAnalyze ($ item_id, $ upload_id), 'item' => $ item, 'upload' => $ upload]);
});


show.blade.php
-------------------------------------------------- -
< a href="{{ route('item.edit', ['item' => $ item])}} "class =" btn btn-primary "> Edit


-
-
-
-
When I change the DB query to the get () function in the route web.php, ie. $item = DB :: table ('items') ->where ('id', $ item_id)->get ();

New ERROR
-------------------------------------------------- -
Facade \ Ignition \ Exceptions \ ViewException
Missing required parameters for [Route: item.edit] [URI: item / {item} / edit]. (View: /var/www/laravel/dev1/resources/views/item/analyzer.blade.php)


REPLY


Hi,

you can try to solve the error in Laravel "Object of class stdClass could not be converted to string" in route / web.php by modifying the selection from DB to instance Item as follows:
'item' => Item::find($item_id)


use App\Item;
...
Route::resource('item', 'ItemController'); // only CRUD
Route::get('/item/analyzer/{item_id}/{upload_id}', function ($item_id, $upload_id) {
$upload = DB::table('uploads')->where('id', $upload_id)->first();
$t = new App\Http\Controllers\ItemController;
return view('item.analyzer', ['results' => $t->handleAnalyze($item_id, $upload_id), 'item' => Item::find($item_id), 'upload' => $upload ]);
});

Související obsah

programovani

php

laravel

databaze

sql

Komentáře

Vaše reakce na PHP Laravel - routing - Object of class stdClass could not be converted to string

Reference

Podívejte se na naše reference

Prohlédnout

Aplikace

Podívejte se na naše aplikace

Prohlédnout

Co umíme?

Podívejte se co umíme

Prohlédnout

Co umíme?

Vytváříme sofistikované aplikace pro náročné

Od webových aplikací přes android až po převodové můstky či složité informační systémy.

Podívejte se k nám

Máte ještě čas? Podívejte se na další rubriky

Tento web používá soubory cookie. Dalším procházením tohoto webu vyjadřujete souhlas s jejich používáním.. Více informací zde.