Laravel how can using the require file - laravel

Laravel how can I use the require file when using #section('content') method, how can I require the file into the this?
I want to using the menu bar, but I don't know how to separate it.
I have this code
<div class="links">
About Me
Employment History
News
Blog
Nova
Forge
Vapor
GitHub
</div>
can independent to menu.php

Make menu.blade.php with this code in your views directory.
In place of code write #include('menu')
If location of file is different then #include('path-to-file') will be loaded.

In Laravel blade you can use #include('file path')

You can use yield() to solve the problem.

Related

Laravel 8 Livewire wire:click:prevent Not Working

Please Someone please I am in the middle of my final year project but this is not working I am trying for 3 days I am new so I don't know how to ask a question so if you need something please ask me Thanks
This is the view for Shop and i have used Composer require Hardevine/shoppingcart
This is the ShopComponent for Shop
When I ran Laravel 8 on IIS, I had a similar problem. The problem was that the browser couldn't access some of the livewire js files, and the solution was:
Go to D:\Projects\Laravel\laravel8ecommerce\vendor\livewire\livewire\config\livewire.php
and set
'asset_url' => "your_url",
and the problem was disappeared.
I had same problem. To solve this issue what I did was enclose my blade template files with a <div> containing an id="main" like so:
<div id="main">
your blade template code
<div>
Instead Of This
wire:click:prevent=“store({{$product->id}},’{{$product->name}}’,{{$product->regular_price}})”
You need to use this in your blade file
#livewireStyles
your code will be in this area
#livewireScripts
Try This For Calling Store Function
wire:click.prevent="store({{$product->id}},{{$product->name}},{{$product->regular_price}})”
Or
wire:click="store({{$product->id}},{{$product->name}},{{$product->regular_price}})”
My solution was based on #KumTem answer
Inside the livewire blades located at app\resources\views\livewire\sample_blade.php
<div id="main">
... templates here
</div>

How to Hide Header in Homepage in Laravel

I am trying to customise a laravel site. I want a different header layout for the homepage. Please how do I do that.
What I currently have is a master layout which include the header layout. What I need is something like this in this website www.jiji.ng as you can see, the homepage header layout is different from the rest of layout. I need a general header for the site but different header for the homepage.
Below is the Master.blade.php code
#section('header')
#include('layouts.inc.header')
#show
#section('search')
#show
There's a variety of ways of doing this.
You could check the current route name. Give your home page route a name, then do:
#if(Route::currentRouteName() === 'home')
#include('layouts.inc.header')
#endif
You could also have multiple layouts for your app, via the #extends keyword.
Your home page route might do:
#extends('layouts.home')
and the rest of the app would do:
#extends('layouts.app')
You can use #component and you can pass any view into it like this:
#component('header')
#include('your_header')
#endcomponent

Laravel (5.2) Blade - How to prevent a Blade Directive in an email address from being parsed?

Update This is a bug in Laravel 5.2 & 5.3
I've got a weird one here. A user's email address on our client's system has a domain with the following substring in it '#parent'. I am not including the whole thing just for the sake of privacy.
Because #parent is a Blade directive, Laravel seems to either process or ignore the #parent and strips it out of the rendered email address on the page.
For example, let's say the email address is john#parentstuff.com. Laravel will render the following on the page: johnstuff.com. See how it removes #parent from the email?
What I've tried to fix it:
1. {!! $user->email !!}
2. {{ e($user->email) }}
I know that this is an issue with Blade as AJAX & jQuery rendered content with this same email address is displayed just fine elsewhere on the site.
UPDATE
Upon further investigation, it appears this may be a bug in how Blade processes the #parent directive. I set up 3 new Laravel projects for the following versions: 5.2, 5.3 and 5.4. The project in question is a Laravel 5.2 project, FYI.
I created the following setup for each of the above mentioned versions to test the bug.
Route
Route::get('/test', function () {
$foo = 'john#parentingstuff.org';
return view('test')->with('foo', $foo);
});
Templates
Base
<html>
<head>
<title>App Name - #yield('title')</title>
</head>
<body>
<div class="container">
#yield('content')
</div>
</body>
</html>
Test View
#extends('test-base')
#section('content')
{{$foo}}
#endsection
Outputs
L5.2: johningstuff.org
L5.3: johningstuff.org
L5.4: john#parentingstuff.org
Theories
One very interesting case I noticed while running these tests was that having the {{$foo}} variable inside of a #section directive vs moving it outside of the #section directive led to two different outputs.
Example
{{$foo}}
#section('content')
{{$foo}}
#endsection
The output of this was...
john#parentingstuff.org
johningstuff.org
Conclusion
So, does anyone know how to patch this bug in Laravel 5.2 or Laravel 5.3? Currently, upgrading to L5.4 is not an option for our client.
Anyone have any clever tricks they can think of that might help?
I believe the problem is elsewhere. You are doing probably something more than you wrote.
Sample controller method content
return view('test', ['email' => 'john#parentstuff.com'];
Sample view:
Email is: {{ $email }}
Result is:
Email is: john#parentstuff.com
so I believe you are doing something more than you wrote.
Something very screwy is going on in your setup, because that shouldn't be possible. Laravel processes Blade instructions before interpreting any variables.
I tested with a very simple example:
Route::get('test', function() {
$foo = 'john#parentstuff.com';
return view('test')->with('foo', $foo);
});
and a Blade template of:
{{ $foo }}
and it works just fine. #parent is not interpreted.
This is a bug in Laravel verions prior to 5.4. See the following:
https://github.com/laravel/framework/issues/10068
https://github.com/laravel/framework/pull/16033
This is a bug in Laravel 5.1 too.
A quick solution could be to change the # sign to
#
to fix it.

What is a blade directive in Laravel?

In a blade template, you see #section, #content, #yield etc. What are blade directives? Are they comparable to PHP or HTML? There doesn't seem to be much explanation on Laravel syntax in the framework.
At a basic level Blade is a templating language that compiles down to PHP and HTML.
When you use #section, #content or #yield in a .blade template file it will be compiled down to PHP.
If you want to dive in exactly to how it works try looking through the tests in frameworks Github or taking a look at the API.

Including CSS in Laravel 5 or 4.3

TL;DR: What is the correct way to link to a stylesheet in Laravel 5?
Background:
I'm using the dev version of Laravel 4.3 (5) because I want to use Socialite, and it makes sense to develop with that from the start. I am having a problem getting templates transferred from 4.2
I've moved my blade layout files to the new directory structure (resources/templates) and placed my CSS in the public/css/ folder.
When I load my route /test/ all I get is "Whoops, looks like something went wrong."
For testing purposes I've removed all blade layout syntax from my layouts - the raw HTML works, but there is no styling (as there is no linked stylesheet). That tells me the routes, views and controllers work.
The problem:
In my layouts, if I remove the following, the layouts work:
{{ HTML::style('css/bootstrap.min.css') }}
{{ HTML::style('css/style.css') }}
Question:
What is the correct location and syntax for Blade Stylesheet inclusion in Laravel 5 and what I should be using instead?
The HtmlBuilder has been removed from Laravel's core, so HTML::style() is no longer available.
If you want to use it in laravel 5, add the following to your composer.json file, under the require key:
"laravelcollective/html": "~5.0"
Also note, since HTML::style() returns HTML code, you don't want it escaped. Use the raw brackets:
{!! HTML::style('css/style.css') !!}
Adding to #joseph's answer, for the users preferring not to switch to the new syntax, you can use
Blade::setRawTags('{{', '}}');
and continue with the old syntax . this can be set almost anywhere, but a better choice would be a service provider, say legacy service provide for l4 . you can find further discussion on this at laracasts, where you can find taylor otwells thoughts on this .
If you want to use plain HTML then use like this-
<link rel="stylesheet" href="/css/folder/style.css">

Resources