Nova was working for me before. I started working on the front-end, and when coming back to Nova it suddenly doesn't work anymore. I can log in, but then it shows the loading animation for all resources and it's not loading data.
I get this error:
Trying to get property of non-object (View: longpath/location.blade.php)
In location.blade.php
#extends('app')
#section('title')
{{ $location->title }}
#endsection
#section('content')
#endsection
The weird thing is that on the front-end, location.blade.php loads perfectly fine, as I pass the $location variable in the LocationController. No errors and nothing in the error log. In LocationController:
$location = Location::
where('id', $this->location_id)
->first();
return view('location', [
'location' => $location
]);
So it shows the error, and this error is in the logs as well. If I comment out {{ $location->title }}, it doesn't show the error anymore, but it's still not loading any data, and nothing shows up in the error log. So I have no clue why it's not loading any data. It's also a mystery to me why a (front-end) Blade template would generate an error in Nova, while it works perfectly fine on the front-end.
Update:
If I comment out this specific route in routes/web, Nova works again. Not sure why this route impacts Nova?
Route::get('/{location_id}/{location_title}', 'LocationController#viewLocation');
If I add the route back in, in my console I get:
TypeError: Cannot read property 'length' of undefined
Your route is problematic because:
Route::get('/{location_id}/{location_title}', 'LocationController#viewLocation');
is going to catch any /foo/bar URL.
If you do php artisan route:list | grep nova you'll see all of Nova's routes, and you'll find a bunch in this format:
/nova-api/metrics
/nova-api/cards
/nova-api/search
/nova-api/{resource}
etc. etc. etc.
(In other words, a bunch of Nova's routes are being sent to your LocationController instead of the right Nova controllers.)
You may be able to fix this by taking the Nova::routes call out of the app/Providers/NovaServiceProvider.php file and putting it in your routes files directly, but the cleaner solution is likely to adjust your route to be something like /locations/{location_id}/{location_title} that's not going to conflict. Wildcarded top-level routes tend to cause issues like this.
You may also be able to do this:
Route::get('/{location_id}/{location_title}', 'LocationController#viewLocation')
->where('location_id', '[0-9]+');
This will make your route only activate for numeric IDs, which means it won't interfere with the non-numeric nova-api routes.
Related
in laravel 8 i will redirect the user to a route after doing the query.
There are many tabs on the page where I want the user to be transferred
I wrote the code like this
(Of course I know it's wrong, but I wanted to try, and yet I did not think of another way
return redirect()->route('admin.auth.user.show', $user . "#edit-information")->withFlashSuccess(__('The user was successfully updated.'));
I get an error with this code
What is your solution?
What you can do to activate for example bootstrap tab based on #web paramater is use the redirect() method like this:
return redirect()->route('backend.settings.show', ['eshop' => $eshop->id, '#homeImages']);
Eshop is regular route parameter but '#homeImages' is added to the end of the route which is then picked up by the js on page load.
In Laravel there is a withFragment method, which add a fragment identifier to the URL.
return redirect()->route('admin.auth.user.show', ['user' => $user])->withFragment('edit-information');
https://laravel.com/api/8.x/Illuminate/Http/RedirectResponse.html#method_withFragment
Route file web.php:
Route::get('/download/received/{image_id}/{isoriginal?}', 'DownloadController#download_recv_image');
View:
<li>Download {{strtoupper($image->extension)}}</li>
<li>Download PNG</li>
Function in controller:
public function download_recv_image($image_id, $original=false){...}
This is function for download received image. When I click on first link in view route is called and function is executed. But on second link where I'am not sending second parameter then it returns me error 404 and it looks like it cant catch route.
(I have another function for download user images, with same logic for route definition in another two links and there everything works.)
I have found where the problem is.
That's because above that route I have another route called:
Route::get('download/{image_id}/{isoriginal?}', 'DownloadController#download_user_image');
I have changed second route to /received/download instead of /download/received
It's messing up because both routes have the same beginning and parameters ar messed up.
I create Laravel+Vue simple REST API web-app.
In Vue component I have a method with an api request.
I simplified this to see the core of the problem:
phpValidate() {
axios
.post("api/validate", self.programmer)
.then(function(response) {
console.log(response.status);
});
}
In the controller I have a method validateIt(), which handle this "api/validate" request.
It returns:
return array('status' => $status, 'data' => $data);
The $status can be equal to 200 or 422, depends on the input data.
The problem is that from some point, it began to return $status of 200 always.
Even if I delete all the code from the method validateIt() and just leave two lines:
$status = 422;
return array('status' => $status);
I still receive 200.
If I delete the whole method in controller, it gives an Internal Server Error 500.
So, the route and function name is correct.
When I put it back, I can write there whatever I like, it doesn't have any sence - it still returns 200!
If I use debugger, I can see that at the end of validateIt() method it returns 422.
But, when I get the response in phpValidate() I see again 200.
Unbelievable!
I tried:
npm run dev
and
php artisan cache:clear
doesn't help!
Also I tried to restart the server and use different browsers, doesn't help.
Actually, this is not a problem of caching.
It looks like the variable name STATUS is reserved.
Doesn't matter what value you give to $status in the controller method.
The $status always contains the actual status of the request and you can't change it manually. Even if the method is empty it will return $status 200 because the request was sucessfull.
The solution is to use another variable name for your own data.
I had the same problem and to solve it add version where you include your vue frontend file,do it like this it will never cache again:
<script src="{{ asset('js/app.js?version='.date("ymdhis").'') }}"></script>
and you should make sure that your vue server is running use npm run watch or npm run dev
Newly installed Laravel 5.5 showing Sorry, the page you are looking for could not be found. without any error . Please see the screenshot :
I think its not even looks into routes file, this is my routes.php and htaccess
What will be the reason for this ?
All your WEB routes will be located in the file:
routes\web.php
Register your routes there.
Order
Pay attention to routes order, it's really important (fooled me so many times to be honest).
Because Laravel goes through list of routes top to bottom until it finds the first match, as a rule of thumb, try to define routes with no parametres first then routes with parameters in your route file (web/api).
Example: (based on Radical's answer)
Route::get('/blog/{id}', 'BlogController#show');
Route::get('/blog/comments', 'BlogController#comments');
In this case, Route::get('/blog/{id}', 'BlogController#show'); comes first so it would be selected. Even when what you really want is Route::get('/blog/comments', 'BlogController#comments');
My two cents :)
I ran into this issue when findOrFail method failed in the Controller method.
Ensure that your register.blade.php is in the resources/views directory and remove the trailing slash from the URL you are assigning to this view.
Sometimes the error messages in the storage/logs/laravel.log log file (if you have the default configuration) can help as well.
There are a lot of reasons why this won't work
Probably the route was written well eg: Route::get('/boost/{type}/{{type_id}}', ['uses' => 'RequestController#getBoosted', 'as'=>'boosts/{{type}}/{{type_id}}']);
when it is meant to be like this: Route::get('/boost/{type}/{type_id}', ['uses' => 'RequestController#getBoosted', 'as'=>'boosts/{type}/{type_id}']);
Looking at the two above code the second route is correct because of the curly brackets are one instead of two
Probably you will be needing to clear your cache which happens at rare occasions
Probably the developer in question did not put the links properly at there controllers Return view('site.block')
you must make sure that the page that is referenced is at the correct location
I think you can use this commands:
php artisan config:cache
php artisan view:clear
these commands use and I hope your error solve
this ones a head ache! From my understanding of laravel's flash method for sessions, once it has been set then called, it will be destroyed...
Session::flash( 'key', $data );
somewhere down the line
{{ Session::get( 'key' ) }}
I am using this for form validation. Now when the form does not validate, the application displayed the error, if I amend the form and post again, the database updates, the details are displayed correctly, but the error appears again! This is the same for if I post the form that doesn't validate, it displays the error, but if I then click the navigation link for the same page, it displays again!
Anyone come across this?
regards
Luke
I had this problem once when I did a return view() / return View::Make when it should be a return redirect()->route() in my Controller#update method.
Since Laravel 5.1, you can use the now() method which will only affect the current request :
Session::now('key', 'message');
or
session()->now('key', 'message');
Out of the laravel docs:
The flash method stores an item in the session that will expire after the next request. It's useful for storing temporary data like status or error messages.
This means, it's available at the current and also the next request. It does not get flushed automatically if you access it. To do so, use Session::flush('key');.
Session Flash preserves the session data for 2 requests because it was meant to be used during redirection.
However, I've came across a use case where I do want to use flash for just 1 request in the next view and found an easy way to do it, which is to pull from the session rather than get it. The Session::pull() gets the session data and removes from the session.
#if (Session::has('message'))
<div class="alert alert-message">{{Session::pull('message'}}</div>
#endif
Hope this helps!
It's probably some other issue with your code, if you could share your code it would help us get a better insight into this issue.
You can use the below code snippet to Flash Error messages to your laravel blade template.
#if (Session::has('message'))
<div class="alert alert-success">{{Session::get('message')}}</div>
#endif
I once had similar issue because i used Session::reflash() in my controller.
Ensure you don't have Session::reflash() somewhere in your controller or anywhere in your application, as it flashes whole session... use example: Session::keep(array('username', 'email')); to reflashing only A Subset Of Flash Data
An easy way to flash a message once when you are creating a view (and not redirecting) is:
Session::flash($key, $value);
Session::push('flash.old', $key);
Refer here.
The flash method is meant for storing the data for the next request. Ideally after flashing the data to the session you should be redirecting to a new route. (This is what the accepted answer suggests.)
But if you are not redirecting you can call the forget method after displaying the session in your blade template:
{{ session()->flash('key') }}
#php
session()->forget('flash-info');
#endphp