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');
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!
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
I cant seem to figure this out. I looked around here and different laravel forums for a solution, but no luck. Hopefully someone can point me in the right direction.
I have a show method in my controller, if I delete a record and redirect back to show, the record will not be found since it has been deleted. So I want to check if eloquent returns a model instance, if it doesnt and returns a null, I would like to redirect to the index page.
Currently with this code, event if eloquent returns a model, my show page is tripping out and keeps reloading, like an endless loop. However, if I take the redirect from the if statement and put in a dd('if statement working') to see if it fails the if statement, it works find. So the issue is with the redirect statement.
Here is a snipped of my show method:
public function show($id)
{
$vendor = $this->user->vendors()->find($id);
//if there are no results redirect to the index page.
if(is_null($vendor)) {
return redirect()->action('VendorsController#index');
}
session()->put('vendor_id', $vendor->id);
return view('vendors.show', compact('vendor'));
}
Any help is appreciated!
public function show($id)
{
$vendor = $this->user->vendors()->find($id);
if($vendor) {
session()->put('vendor_id', $vendor->id);
return view('vendors.show', compact('vendor'));
}else{
//redirect to index
return redirect()->action('VendorsController#index');
}
}
I have a show method in my controller, if I delete a record and redirect back to show
How about you modify your delete/destroy method, then send it directly to your index page after delete.
I'm attempting to create a custom display in yii2 framework using this code in my site controller:
/******/
public function actionChartDisplay()
{
return $this->render('chartDisplay');
}
for testing purposes I pasted the form name in my actionAbout function as a parameter to the render function in it. It worked with this:
public function actionAbout()
{
return $this->render('chartDisplay');
}
But I need to create many custom views in yii2 and this won't be a solution.
This is the error I get
I'm curious as to why it is. Since I was following this tutorial and came across this weird behaviour.
My 'chartDisplay.php' file is merely a "hello world" that does work with the action about function.
in yii2, the controllers and actions with multiple words, that are marked by capital letters are divided by - in your request, so in your case the route would be some/chart-display
Apparently as #SmartCoder pointed out it was an error on how Yii2 Handles the action functions in its controller however I didn't mark his answer as the solution right away because implementing it resulted in an error. So aside from that I'm posting the way I solved it.
So instead of using chart-display I simply changed it for "charts" like this:
public function actionCharts(){
return $this->render('charts');
}
Changed the name of my file so it fits to charts.php and it worked.
I'm trying to return search results to a new controller than where the search action was performed from. Problem is Results is never accessible from CustomSearchResultPage.ss. I've added inline comments for what I think is happening, am I right in my thinking here?
// Customise content with results
$response = $this->customise(array(
'Results' => $results ? $results->getResults() : '',
));
if ($results) {
$response = $response->customise($results);
}
// Use CustomSearchResultPage.ss template
$templates = array('CustomSearchResultPage', 'Page');
// Create a new CustomSearchResultPage page
$page = CustomSearchResultPage::get_one('CustomSearchResultPage');
// Build a controller using the CustomSearchResultPage
$controller = CustomSearchResultPage_Controller::create($page);
// Add the custom data to the newly minted controller
$result = $controller->customise($response);
// Return the controller and tell it how to render
return $result->renderWith($templates);
The page seems to render as expected just the variable is always empty...
Your explanation is a little hard to follow I'm afraid. So I'm answering for what I can ascertain as below:
Performing a search. This requires loading a controller to do as such.
Customising the current controller with the results
RE-customising the current controller with itself.
Setting the template for the current (double customised) controller.
Disregarding all of the above.
Fetching a random page (or an empty record).
Creating a controller for the empty page.
Customising the new controller with the customised controller of the current controller customised with itself.
Returning that page, which shows no results.
You need only stop at step 4 (skip step 3), and return the customisation ($response).
If there is some reason you think you need another controller however (which seems superflous, but who knows), creating and then customising that one (only) before returning it would be better.
Being that you have only used this second controller for rendering a result, the URL will not have changed or anything. The whole thing seems beyond requirements.
A much more simple way to render a result from this action would probably be:
return $this
->customise(['Results' => $results ? $results->getResults() : null])
->renderWith(['CustomSearchResultPage', 'Page']);
(from the top of my head, may need a little refining).