I am using Laravel Blade on my page and for some reason, the isset function isnt working properly. If the variable is not set, it triggers an error. Here is my code so far:
#if (isset($returns['Passive'])) //This is where the error is occuring
<ul class="list-group">
<li class="list-group-item"><span>Passive Income</span>
<ul class="list-group">
<li class="list-group-item"><span>Passive: {{ $returns['Passive'] }}</span></li>
</ul>
</li>
</ul>
#endif
I have no idea why it would cause an error, I have used isset on multiple pages before and it has never been an issue. Here is the error I am getting:
ErrorException: Undefined index: Passive (View: /home/unlikem5/public_html/myuladmin/resources/views/misc/paidPositions.blade.php) in /home/unlikem5/public_html/myuladmin/storage/framework/views/fc6ec53af49c1252e1698dacf9ac958b628485d5.php:16
Try this command and run again this will defenately solved your issue.
Clear all compiled view files:
php artisan view:clear
php artisan cache:clear
Laravel provides blade directives for isset and empty functions. Try this out -
Laravel 5.6 Docs
#isset($records)
// $records is defined and is not null...
#endisset
#empty($records)
// $records is "empty"...
#endempty
Related
I was trying to extend my user.blade.php to my views menu.blade.php. Everything works fine with my other views that use the same user.blade.php too. But not with my menu.blade.php, I get an error saying "Undefined variable: categories (View: D:\xampp\htdocs\mieaceh\resources\views\layouts\user.blade.php)" with "Possible typo $categories
Did you mean $errors?"
Here are the codes to my user.blade.php
#foreach($categories as $category)
<a href="{{ route('menu.index', ['category' => $category->slug]) }}">
<div class="card-category" style="width: 10rem; height: 4rem;">
{{ $category->name }}
</div>
</a>
#endforeach
How do I solve it?
If you want to make a piece of view that appears in multiple places, you can use blade components https://laravel.com/docs/8.x/blade#components.
This will help encapsulating this partials behavior and required data.
Checking generated html of my laravel 5.7 app in https://validator.w3.org I got errors like :
Error: Bad value navigation for attribute role on element ul.
From line 353, column 21; to line 353, column 61
<ul class="pagination" role="navigation">↩
Searching for similar code in my application I found several files like
vendor/laravel/framework/src/Illuminate/Pagination/resources/views/bootstrap-4.blade.php with code
#if ($paginator->hasPages())
<ul class="pagination" role="navigation">
as this file is under /vendor directory, if there is a way to fix it for my app ?
Thanks!
You can run php artisan vendor:publish --tag=laravel-pagination, it will create pagination view in resources/views/vendor/pagination folder. Then you can customize and use it by adding to the first argument of links() method.
List view:
<div class="content">
#foreach($posts as $post)
..blahblah..
#endforeach
</div>
{{ $posts->links('vendor.pagination.view_name') }}
More here:
https://laravel.com/docs/5.7/pagination#customizing-the-pagination-view
I am using alaouy/Youtube package on Laravel 5.4. It's fetching videos from Youtube but I am getting errors.
// view
#extends('welcome')
#section('content')
<ul>
#foreach($videos as $data)
<div class="well">
{{ $data->id->videoId}}
</div>
#endforeach
</ul>
#endsection
// controller
$videos = Youtube::search($search);
return view('search',compact('videos'));
I am able to get access to all the data in the object except {{$data->id->videoId}}
// Error
Undefined property: stdClass::$videoId (View:
C:\Users\derrick\testyoutubeapi\resources\views\search.blade.php)
You are not receiving the required data so you are getting the error message of not defined property.
in other words, you are requesting videoId field which is not there for some of kinds like playlist (playlistId), or maybe a channel (channelId)
so your problem solution should be just making your code in the view to check if there is a field that is called videoId or no before the query:
#foreach($videos as $data)
#if(isset($data->id->videoId)) // field available?
<div class="well">
{{ $data->id->videoId}}
#endif // end if
</div>
#endforeach
I am trying to render my view but i got error
its says Method render does not exist . (View:
my view is
#foreach($forumindex->forumindex()->paginate(2) as $comment)
<p><div class="well">{{ $comment->comment }}</div></p>
#endforeach
{!! $forumindex->forumindex->render() !!}
when i remove {!! $forumindex->forumindex->render() !!} its working fine and i see only 2 post
help me i don't know what code is right
The render() method to build the paginator view has been renamed to links() on Laravel 5.2.
Source: https://laravel.com/docs/5.2/pagination
I have the following blade code:
<a href="{{ route('settings') }}">
<span class="title">Settings</span>
</a>
I have the following defined at the top of my routes.php file:
Route::post('settings/update', 'SettingsController#update');
Route::resource('settings', 'SettingsController');
When I try to go to any page with route('settings') I get a Route [settings] not defined error.
If I do php artisan routes I can see that the settings routes are all there as expected.
With route('settings') you refer to a route named settings but you don't have such a route. RESTful routes will automatically receive a route name though.
For the index method it is resource.index for the show method resource.show and so on.
Change your code to this:
<a href="{{ route('settings.index') }}">
<span class="title">Settings</span>
</a>
Change {{ route('settings') }} to {{ URL::to('settings') }}