class MyController extends Controller {
private $data;
index() {
$data = (object)[];
$this->data = $data;
return compact();
}
otherRouteMethod() {
dd($this->data);
}
}
ROUTES
Route::get('/my', MyController::class . '@index')->name('my.overview');
Route::get('/my/sub_route', MyController::class . '@otherRouteMethod');
Why is the following happening?
- Both routes work
dd($this->data)prints "null" as it was not set in index()- using
publicmodifier for $data leads to the same issue
Is it because Laravel makes a new instance of the class on every route change?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NUTLv3
via IFTTT
Aucun commentaire:
Enregistrer un commentaire