How to define a link in laravel? - laravel

Hello I am new bee in laravel. I have an <a> tag. I want to give link in controller. I wrote
<a href="{{ URL::to('/controller'); }}">
But it prints same in addressbar:
http://localhost:8000/{{ URL::to('/CategoryController'); }}
My routes.php file is OK.
Should i need to change in any other file ?

Related

how to use {{}} inside of asset helper laravel

I have a dynamic image that a user can change, so I need to grab the path from the database. Everything works fine if I do:
<img src="/storage/{{ $client->image->path }}">
But this doesn't work:
<img src="{{ asset('/storage/{{ $client->image->path }}') }}">
Thank you for your help
You've already opened the curly braces once. You can process it in accordance with the syntax. Try like this:
<img src="{{ asset('/storage/' . $client->image->path) }}">

laravel : Pass information with key in url

Hello i want to make url like example.com/overview-schedule?=user_key=123456 in laravel. I do not know how to do it.
Sharing my code :
In blade.php define a link
<a href="{{ route("overview-schedule") }}">
on my web.php
Route::any('overview-schedule', 'Front\PlanController#scheduleOverview')->name('overview-schedule');
Got an error
InvalidArgumentException
Route [overview-schedule?user_key=123456] not defined.
How can i do it ?
use url() helper method
$user_key = 123456;
<a href="{{ url('/overview-schedule?user_key='.$user_key) }}">
You can pass an array of parameters to route function :
<a href="{{ route("overview-schedule" , ['user_key' => $user_key]) }}">
You should try this:
<a href="{{ url('/overview-schedule?user_key='.$user_key) }}">

Laravel Blade: use $variable or 'xxx' inside asset()

I want to change the logo in my header on certain pages.
I'm therefore extending my layout like this:
#extends('templates.main', ['logo' => 'img/logo/logo_red_white_text.png'])
In my layout when no $logo isset it uses the default one:
<img src="{{ asset($logo or 'img/logo/logo_yellow_white_text.png') }}" alt="">
However this doesn't work. It only works when I remove asset() but then the logo will not be shown when using a prefix (for example app.dev/en/mypage), so I need asset.
What can I do?
Here is the solution:
<img src="{{ asset(isset($logo) ? $logo : 'img/logo/logo_yellow_white_text.png') }}" alt="">
Unfortunetelly you can use or laravel's blade statment only for echoing like this:
{{$logo or 'img/logo/logo_yellow_white_text.png'}}

Laravel Blade html image

My image file path is public/img/stuvi-logo.png and
my app.blade.php file path is resources/views/app.blade.php
Inside of my app.blade.php file I use {{HTML::image('/img/stuvi-logo.png')}}
to display an image.
I don't understand why this won't find the image.
What is the root folder of the image() method?
If you use bootstrap, you might use this -
<img src="{{URL::asset('/image/propic.png')}}" alt="profile Pic" height="200" width="200">
note: inside public folder create a new folder named image then put your images there. Using URL::asset() you can directly access to the public folder.
Change /img/stuvi-logo.png to img/stuvi-logo.png
{{ HTML::image('img/stuvi-logo.png', 'alt text', array('class' => 'css-class')) }}
Which produces the following HTML.
<img src="http://your.url/img/stuvi-logo.png" class="css-class" alt="alt text">
Update After Laravel 5 this package has been deprecated and maintained as a separate external package. in order to work need to add this composer require laravelcollective/html. more details https://laravelcollective.com/
as of now, you can use
<img src="{{ asset('images/foo.png') }}" alt="tag">
In Laravel 5.x you can use laravelcollective/html and the syntax:
{!! Html::image('img/logo.png') !!}
It will look for an image inside of a public/storage folder where you can define your own image folder
<img src="{{ Storage::url($post->image->path) }}" alt="">
Always try to dump what you are looking for first and than pass it to a url method.
Also, you can create your own url() method inside your Image model if you have some
public function url()
{
return Storage::url($this->path);
}
Then in your blade template you can use this method as follows:
<img src="{{ $post->image->url() }}" alt="">
Had the same problem with laravel 5.3...
This is how I did it and very easy.
for example logo in the blade page view
****<image img src="/img/logo.png" alt="Logo"></image>****
In Laravel 5.x, you can also do like this .
<img class="img-responsive" src="{{URL::to('/')}}/img/stuvi-logo.png" alt=""/>
you can Using asset() you can directly access to the image folder.
<img src="{{asset('img/stuvi-logo.png')}}" alt="logo" class="img-size-50 mr-3 img-circle">
in my case this worked perfectly
<img style="border-radius: 50%;height: 50px;width: 80px;" src="<?php echo asset("storage/TeacherImages/{$studydata->teacher->profilePic}")?>">
this code is used to display image from folder
Assuming the file you want to display is public try adding the variable in your Mail builder function.
public function toMail($notifiable)
{
$img_url = env('APP_URL')."/img/stuvi-logo.png";
return (new MailMessage)
->subject('Test')
->markdown('vendor.mail.markdown.message', [
'data' => $this->data,
'img_url'=>$img_url
]);
}
And then use your 'img_url' variable set in the array in your email blade file.
< img src={{img_url}} alt="Logo" height="50"/>
This worked for me on Laravel 8.xx.

Laravel route not defined error even though it is

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') }}

Resources