How to modify code under vendor/ directory - laravel-5

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

Related

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'fingerprint') Laravel Livewire

I've made a multiple file-upload component using Laravel Livewire. After the upload is complete I want to display the uploaded files without reloading the page, like so:
<div class="grid grid-flow-col auto-cols-max gap-4 mb-5">
#foreach ($files as $file)
<livewire:file :file="$file"/>
#endforeach
</div>
Uploading one or multiple files at once works fine. But while uploading when there are already files present in the loop, Livewire throws this error: Uncaught (in promise) TypeError: Cannot read properties of null (reading 'fingerprint').
After doing some research I came to the conclusion that this is caused because Livewire generates the same id as the first file:
<div class="grid grid-flow-col auto-cols-max gap-4 mb-5">
<div wire:id="eCHZ9wxyp7nxOC4o5uCC" class="file file-jpeg file-lg">
<!-- content of existing file component -->
</div>
<div wire:id="eCHZ9wxyp7nxOC4o5uCC" class="file file-jpeg file-lg">
<!-- content of new file component, should have Unique wire:id -->
</div>
</div>
How to fix this issue?
This issue first occurred in september 2020 and was dissolved (reference: https://github.com/livewire/livewire/issues/1686). The error occurred because the new file is not unique to the existing file. The solution mentioned on Github works but is outdated.
If you are on Laravel 7 or above, you can add :wire:key="$yourUniqueKey" to the livewire component inside the loop:
<div class="grid grid-flow-col auto-cols-max gap-4 mb-5">
#foreach ($files as $file)
<livewire:file :file="$file" :wire:key="$file->id"/>
#endforeach
</div>
Reference: https://laravel-livewire.com/docs/2.x/nesting-components
I solved the issue by passing time in the key variable
<div class="grid grid-flow-col auto-cols-max gap-4 mb-5">
#foreach ($files as $file)
<livewire:file :file="$file" :wire:key="time().$file->id"/>
#endforeach
</div>

Laravel Blade isset triggering error

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

Is it possible to delete record without using forms in laravel 5.4

I want to delete a record but I haven't been successful, apparently my code is wrong. Solutions i came across say i have to use a post in my form method and add the method_field helper. This would mean my view having a form in it, i want to avoid this if possible. Is it then possible to do my delete another way. Below is my code
snippet of my view
<div class="backbtn">
<a class="btn btn-savvy-delete" href="/tasks/{{$task->id}}" data-toggle="tooltip" title="Delete"><i class="fa fa-trash-o" aria-hidden="true"> Delete</i></a>
</div>
<div class="panel-body">
<p><strong>Owner:</strong> {{ ucfirst($task->employee->firstname) }} {{" "}} {{ ucfirst($task->employee->lastname) }}</p>
<p><strong>Task:</strong> {{ $task->title }}</p>
<p><strong>Description:</strong> {{ $task->description }}</p>
</div>
TaskController
public function destroy($id)
{
Task::destroy($id);
Session::flash('status', "Task was successfully deleted.");
return redirect('/tasks');
}
web.php
Route::delete('/tasks/{id}', 'TaskController#delete');
Im not sure what error you are getting, but i can point out a few things. For one use Route::get instead of ::delete, you are calling it via a link not a form method.
Secondly to delete follow what the laravel doc says here eg.
$task = App\Task::find(1);
$task->delete();

Laravel Blade - yield inside section

I'm trying to yield a section inside another section. But this does not work as expected, I see blank output.
#section('3show')
This is a text string
#stop
#section('page-content')
<div id="content">
<article>
#yield('3show')
</article>
</div>
<!--#content-->
#stop
Any ideas to yield section inside another section ?
Ok, this is what I tried and I can confirm that this works, at least for Laravel 5+ (I have L5.2). This is how I suggest you to use your blade templates.
Lets start saying that to yield a section into another section you have to define your included section before container section definition. So, with that clear, I solved this situation like this:
I got a main blade (main.blade.php) template which has something like:
<section class="content">
<!-- Your Page Content Here -->
#yield('main-content')
</section><!-- /.content -->
I got a second blade (common.blade.php) template which has that common stuff you may want to show across many pages and where main-content section is defined. This one looks like:
#section('main-content')
<div class="container">
#yield('extra-content')
</div>
#endsection
Finally I got a 3rd template (test.blade.php) which extend the main template and include the common stuff I want to show, but be careful because the order matters. This one looks like:
#extends('main')
#section('extra-content')
<div>
<span> This is a test! </span>
</div>
#endsection
#include('common')
In your controller or your route (wherever you return your view), you should return the 3rd template.
In my projects i create some partials in order to have cleaner code and i give them as an example a name : 3show.blade.php. In order to use them in a section i just include them.
I think this will do what you want.
#section('content')
#include('3show.blade.php')
#endsection
I had the same issue.
You can't use the #extends option in this case, you need to use #include .
So lets say you have:
the root layout (layouts/app.blade.php)
an extra layout (layouts/extra.blade.php)
the actual view that you are calling (someview.blade.php)
The solution is to use add/inherit the root layout (1) to the top line of your view (3):
#extends('layouts.app')
Next, add/inherit the extra layout (2) to the second line of your view, BUT use #include not #extends:
#include('layouts.extra')
...and remember to wrap the content of your extra layout in an #section name, for example #section('extra')
Finally you can call your extra layout content from your view:
<p>Look below, you will see my extra content...</p>
#yield('extra')
So in summary, your someview.blade.php view would look like:
#extends('layouts.app')
#include('layouts.extra')
#section('content')
<p>Look below, you will see my extra content...</p>
#yield('extra')
#endsection
solution 1:
you can use #show instead of #stop at the end of section
then laravel will render your #yield parts ...
like this :
#section('page-content')
<div id="content">
<article>
#yield('3show')
</article>
</div>
#show # not #stop
#section('3show')
This is a text string
#stop
this way render you view and show result
so if you cll your section for twice then result will be shoed twice
solution 2:
insert call section before yiel it
like this :
**first call section :**
#section('3show')
This is a text string
#stop
**then define your section : 3show**
#section('page-content')
<div id="content">
<article>
#yield('3show')
</article>
</div>
#stop **not #show**
assume you have two files:
-article_base.blade.php -> the default data in every article.
-article_index.blade.php -> the customized file.
article_base.blade.php
#extends('layout')
#section('page-content')
<div id="content">
<article>
....
#yield('3show')
....
</article>
</div>
<!--#content-->
#stop
article_index.blade.php
#extends('article_base')
#section('3show')
This is a text string
#endsection
I hope this works
You have to both #include and #yield the child template in your main template to be able to add the child template at a specific place inside the main template (not just before or after the main template - this is done by adding #parent in the child template - but in between):
main.blade.php
#include('child')
<div>
...
#yield('child')
</div>
child.blade.php
#section('child')
<div>
...
</div>
#endsection

Laravel included template is not parsing / running foreach loop

I have included a couple of files.
my home.blade.php has the following:
#include('includes.header')
my header.blade.php in includes folder has the following
#include('elements.pendingTasksLi', array('tasks'=>$tasks))
and my elements/pendingTasksLi.php file has the following
#foreach ($tasks as $task)
<li>
<a class="todo-actions" href="javascript:void(0)">
<i class="fa fa-square-o"></i>
<span class="desc" style="opacity: 1; text-decoration: none;">{{{$task\['title'\]}}}</span>
<span class="label label-danger" style="opacity: 1;"> {{{$task\['deadLineTime'\]}}}</span>
</a>
</li>
#endforeach
This code in the pendingTakstsLi file is never executed as a loop but only as a simple text.
This is what the output looks like...
#foreach ($tasks as $task)
{{{$task['title']}}} {{{$task['deadLineTime']}}}
#endforeach
I am not sure what to do... Please advise...
Check a screen here
http://i.stack.imgur.com/8emZk.png
Thanks
Jyot
You mentioned that your "pendingTasksLi" view ends in ".php" and not ".blade.php" which would prevent it from being parsed as a blade view.
I had the same problem and as mentioned above you forgot the .blade before the .php
If you want to use expressions like this: {{ $variable}} and want them to be parsed you always have to add .blade in the name pefore the .php extension of the file.

Resources