Currently I'm working on a Laravel project and I try to return a view in my controller. So far, so good.
But, when I really want to show the data from the view, nothing gots returned. It only shows a white screen.
So, what can be the problem? I don't know yet.
This is my current code
public function show(Domain $inputDomain)
{
$domainId = Domain::where('domain', $inputDomain->domain)->firstOrFail()->id;
$scanId = Scan::where('domain_id', $domainId)->firstOrFail()->id;
$result = Result::where('scan_id', $scanId)->firstOrFail();
return view('detail');
}
The last return does not work, it does not show the view.
Good to know:
1. When I just dump (dd) true, it works and I see the true-message
2. The view really exists and it contains data (I also tried to replace the blade template with some 'lorem ipsum' data, but also that did'nt show up)
When I just do a dd on the View::render (made an $view variable and did dd($view->render()) it shows me the HTML (in the DD screen), but when I return it, it is empty.
Comments
According to a comment I want to show the Route that I'm using
Route::get('{domain}', 'DomainController#scan');
According to a comment, I also want to show that I point to a file in the root of views/
How can I show the view to the visitor?
Also good to know, (forgot to mention)
This is my #scan function
public function scan(Domain $domain)
{
Dispatch(new ProcessScan($domain));
$this->show($domain);
}
Found the problem
I forgot to return the data in #scan
Changed the code to
public function scan(Domain $domain)
{
Dispatch(new ProcessScan($domain));
return $this->show($domain); //Added return
}
And it is working
Related
I have a route set up correctly... I know because the dd($dev) shows me the model instance when not commented out. ($dev is a model instance that is successfully grabbed after translating the slugs in the URL in other funcitons before getting to show)
When I view the page/route with dd($dev) commented out, I get a blank page! No error.
DevelopmentController.php:
public function show($dev){
if(is_numeric($dev)) $dev=Development::find($dev);
if(!is_object($dev)){
dd('ERROR: No development found ', $dev); // TODO handle error
}
if (View::exists('development')) {
// dd($dev); this shows development model instance OK!
return view('development' , ['development'=>$dev]);
}
dd("View doesn't exist");
}
I have confirmed the view works with the following route which displays the view correctly;
Route::get('/test', function () { return view('development', ['development'=>Development::find(228)]); });
/resources/views/development.blade.php:
<x-layout>
<h1>Development: {{$development->description}}</h1>
</x-layout>
I have other controllers displaying their views successfully.
I must be missing something obvious, but struggling to spot it!
Any ideas?
Just for reference, I was stupid and returning the view from the show function, but not returning that value back to the route.
public function findShow($countySlug, $locationSlug, $developmentSlug){
$dev=$this->find($countySlug, $locationSlug, $developmentSlug);
return $this->show($dev);
}
Also didnt' help that I didn't put this in the question. Sorry!
wanna ask for pagination. Why my pagination is not working, when I click the 2nd number in pagination it tells "NotFoundHttpException in RouteCollection.php" and the design is also just a number, cant render the design. I'm using Bootstrap 4.
Here's my controller
function searchuser(Request $req){
if($req->has('searchuserr')){
$data = User::where('name','like','%'.$req->input('searchuserr').'%')->select('name','email','status', 'pp', 'gender')->orderBy('name')->paginate(4);
$data->setPath($req->url()."?search=".$req->searchuserr);
return view('Users.searchuser')->with('data', $data);
}
else{
return redirect('Users.searchuser');
}
}
and my routes for these function
Route::get('/searchuserpage', ['uses'=>'searchController#searchuser']);
in my pages i wrote this {{data->links()}}
You are making mistake in your setPath() method. The query you are using is "searchuserr" and you added "search" for pagination.
Your code
$data->setPath($req->url()."?search=".$req->searchuserr);
The code should be
$data->setPath($req->url()."?searchuserr=".$req->searchuserr);
Note:
You are might also making mistake on else condition.
return redirect('Users.searchuser');
Bit of an odd problem which is probably because I am finding my feet with Laravel.
I have an edit page which is accessed by:
Route::get('editRow/{id}', function($id){
$section = App\Section::where('id', $id)->with('panels')->first();
return view('front.editrow',['thesection'=>$section]);
});
This form then is completed and goes to a controller with a longish method to update the table and ends with:
return view('front.editrow',['message'=>'update successful','id'=>$request->id]);
The DB is updated OK. Initially I was getting an error so I copied the route and changed it from a get to a post:
Route::post('editRow/{id}', function($id){
$section = App\Section::where('id', $id)->with('panels')->first();
return view('front.editrow',['thesection'=>$section]);
});
Now although this is exactly the same parameters etc I always get;
Undefined variable: thesection
I am baffled and would greatly appreciate this mystery being solved!
Make sure that thesection variable is always passed to the view.
When you do:
return view('front.editrow',['message'=>'update successful', 'id'=>$request->id]);
this variable is not provided. You need to either provide it in the view or check for its existence in the blade template with:
#if(isset($thesection)
// whatever you want to do with the section
#endif
I am trying to add the view action to my back office module page but i cannot display anything with the renderview() function. I can already display my list with renderList() and it's working well. I also tried renderForm() and it works well too but it seemz i can't get renderView() to display something.
public function renderView(){
if(!($config = $this->loadObject())){
return;
}
$data = Config::getDataForm(Tools::getValue('id_config'));
// var_dump($data);
$this->tpl_view_vars = array(
'id_config' => $data['id_config'],
'prix' => $data['prix'],
'hauteur' => $data['hauteur_passage']
);
return parent::renderView();
}
This is a pretty basic code. My getDataForm($id_config) is getting fields from database in an array so that i can display it. I can see the var_dump displaying for a short time before displaying the blank page with prestashop header and footer. I tried to see if i was doing something wrond by checking other AdminController such as AdminCartsController or AdminCustomersController but it seems that their renderView() function is more or less written the same way.
Thanks in advance for your help !
I manage to resolve this problem simply by adding a view tpl in /modules/mymodule/views/templates/admin/mymodule/helpers/view/.
I wrongly assumed that it didn't need to create a template file for the view action as it didn't need one for the list and form action. After searching through modules and admin files i managed to find that there were indeed a custom view.tpl for the view action.
The renderview() method lets you set up the variables you want to use in your view.tpl.
For more information on how it works, you can check AdminCustomersController to see how it is on the controller side and /adminxxxx/themes/default/template/controllers/customers/helpers/view/view.tpl to see how the template is written.
Feel free to edit or comment if you need more information
If you want to add a configuration page on your module, you'll have to add this function to your module :
public function getContent()
{
// return some html content
}
If you want to use a controller, then you'll have to create a Controller that extends ModuleAdminController and add it in the tabs of the back-office.
Hello I have created a website with the Laravel 4 framework and somehow since yesterday there is a problem with 1 view on the production server.
When the controller returns a view like
return View::make('site/reservation/vehicle')
it actually stays on the same page as before and does not redirect me to vehicle page. When I replace the view with a simple String I do get the value of the string though.. the whole method looks like this
public function getDates() {
$value = Session::get('reserveringen');
return View::make('site/reservation/vehicle')
->with('gegevens', $value)
->with('vehicles', $this->vehicles->getVehicleByDate($value['pickupsub'], $value['returnsub']));
}
The same code works like a charm on the dev server. Is there anything that could cause this problem ?