Hey,
So I'm pretty fresh to Laravel, and now I'm trying to dynamically generate the edit view of the admin interface. Basically, what I want to do is use commands to enter the edit view of a specific post. However, when I attempt to return the view in a function called by my handle, I get a blank page.
Route::get('admin/event/{id}', 'AdminController@editEvent');
public function editEvent($id, EditEventCommandHandler $handler)
{
$command = new EditEventCommand($id);
$handler->handle($command);
}
class EditEventCommand extends Command {
public $id;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct($id)
{
$this->id = $id;
}
}
class EditEventCommandHandler {
public $event;
/**
* Create the command handler.
*
* @return void
*/
public function __construct(Events $event)
{
$this->event = $event;
}
/* Helper functions */
public function displayEvent($id)
{
$event = $this->event->fetchEvent($id);
return view('admin.editEvent', compact('event'));
}
/**
* Handle the command.
*
* @param EditEventCommand $command
* @return void
*/
public function handle(EditEventCommand $command)
{
$id = $command->id;
$this->displayEvent($id);
}
}
So, does anyone have a clue of what I'm doing wrong? Or even better, how I solve it? I'm guessing views cannot be returned from handlers or something similar? But then, how do I do this?
Cheers
You probably solved it allready but since it might be helpfull for others: You were returning the view from the command back to the controller, but the controller does not return a response, thus leaving you with a blank page...
Solution: Return the response of the handler in the controller as well.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community