I'm calling a blade that way:
<a href="{{ asset('views/quem-somos.blade.php') }}" class="dropdown-toggle"
data-toggle="dropdown">Quem somos</a>
but is returning that in the file does not exist, how would the correct way of calling in href be?
You shouldn't be calling the view files like that, create a url in the routes.php/web.php depending on your laravel version and have the url point to the blade instead.
Route::get("/quem-somos", function() {
return view("quem-somos");
});
And in the current file, change the link to
Quem somos
Use #include('quem-somos') wherever you're wanting the blade to be inserted.
Related
I am currently on
http://127.0.0.1:8000/cars/
I have a link that has to route me to
http://127.0.0.1:8000/cars/create
I used this in my code
<a
href="cars/create"
</a>
In my web.php I have following route
Route::get('cars/create',function ()
{
return view('carsops.create');
});
When I click on link I am redirected to
http://127.0.0.1:8000/cars/cars/create
Instead of
http://127.0.0.1:8000/cars/create
What is the error why I am getting this extra /cars.
Can some one help me.
You have to put a / in front of the link:
<a
href="/cars/create"
</a>
This means Go to the site root, then got to cars path then go to the create path.
This is solution is not nice. Why? Ok, you should use route names in the your application.
How to solve this problem correctly?
A first step is set name to your route. Modify routes/web.php like to
Route::get('cars/create',function ()
{
return view('carsops.create');
})->name('carsops.create');
Look at the name. Name can be as you wish.
Step 2 is, calling your route in the blade like to
<a
href="{{ route('carsops.create') }}"
</a>
Well done.
Laravel a href links are made by giving name,
if you want a return view without variables you don't need to get a method
Route::view('cars/create','carsops.create')->name('yournamelink');
use in blade page
goto page
A root-relative URL starts allway with a / character, to look something like create car.
The link you posted: create car is linking to an folder located in a directory named create in the cars, the directory cars being in the same directory as the html page in which this link appears.
It is therefore easier to work with Laravel Helper. As already mentioned here.
<a href="{{ route('car.create') }}"</a>
You define the route names in your web.php and for api links in your api.php file.
Route::get('/create-car', [App\Http\Controllers\PageController::class, 'create'])->name('car.create');
Hi I am new to php programming. I am using laravel 5.2 now.
I have used an external service to create a pdf from my html page. For that I have used pdfcrowd. I wrote the content to a pdf file in my local system. Its location is /var/www/html/testproject/test_pdf.pdf.
It works fine. Now my requirement is that, I have to open that pdf file in a new tab from my controller. My controller name is adminController. Inside that I used a function to open the pdf.
Please see the code below:
public function open_pdf() {
$file_location='/var/www/html/testproject/test_pdf.pdf';
----------?
}
Please suggest your ideas.
The important thing to understand is that, we can't open a new tab from php controller. So In the view page (testpage.blade.php) I used 'target="_blank" code in a tag. please see the code below:
<a href="{{ url('/') }}/testproject/openpdf"> target="_blank"
Try to add target="_blank" in your html tags it will work fine.
You may have use like this
<a href="{{ url('/') }}/testproject/openpdf">
please try with this
<a href="{{ url('/') }}/testproject/openpdf" target="_blank">
I have a Laravel 5.1 project that I'm trying to improve and now migrating some features to Vue.js to make it more interactive and stuff.
In my view I have
<img src="{{ file_storage_path($product->path) }}" alt="{{$product->name}}"/>
This is default implementation using Laravel's blade.
Now, when I delegate this to the Vue.js I would have something like this
<img src="{{ file_storage_path(product.path) }}" alt="#{{product.name}}"/>
But this of course fails. So I need both - to invoke a php-function and at the same time to render Vue data.
I tried this
src="{{ file_storage_path( #{{product.path}} ) }}"
But of course this fails too. any suggestions?
Since I couldn't find a way to inline both blade syntax and Vue.js variable rendering I see the solution is to first invoke the php function and then append the Vue.js rendering to it.
So, the workaround would be
<img :src="'{{ file_storage_path('/') }}' + image.path" alt="#{{product.name}}" />
This solution would work only for specific case, it doesn't get answer to my original question, when a php function actually needs to accept a Vue variable. But in this case, I can simply append values.
I am currently generating my application urls using {{action('Namespace\Class#method')}}. How would I check if the current page request maps to that current action Namespace\Class#method?
I would like to do something like:
<a href="{{action('Namespace\Class#method')}}
#if (currentAction('Namespace\Class#method'))
class="active"
#endif
>Some link</a>
How would I achieve this in Laravel 5?
There's no built in method for this, however you can retrieve the current action name with Route::currentRouteAction(). Unfortunately this method will return a fully namespaced class name. So you will get something like:
App\Http\Controllers\FooBarController#method
You can either check for that or use something like ends_with so you don't have to specify the full path:
#if(ends_with(Route::currentRouteAction(), 'FooBarController#method'))
You might also consider naming your routes with 'as' => 'route.name'. This would allow you to use: Route::is('route.name')
Actualy I had it simplified to the following code:
<li class="#if(Route::is('getLogin')) active #endif">Login</li>
That assumes that you have named routes. Which is a good idea in the first place, because you migth change the url of an action without going through your whole project to change the links to that action.
I know this is old, but for what it is worth.
Laravel has a couple of built-in helper methods for referring to URLs action and route.
action
Your route file would look like this.
Route::get('/funtastic', 'FuntasticController#show');
Your blade view would look like this
<a href="{{action('FuntasticController#show')}}
#if(action('FuntasticController#show') == Request::url())
class="active"
#endif
>Some link</a>
route
If you use named routes.
<a href="{{route('namedRoute')}}
#if(route('namedRoute') == Request::url())
class="active"
#endif
>Some link</a>
This is how I do it without any named routes
<a class="{{ str_contains(request()->url(), '/some-page') ? 'active' : '' }}" href="/some-page">Some Page</a>
This is not a perfect solution but it works for most cases
It works perfectly for me.
<a class="#if (\Route::current()->getName() == 'device_media') active #endif" href="{{ route('device_media', ['brand_slug'=>$brand->slug, 'slug'=>$device->slug]) }}" > Media</a>
This is working fine to show all the images inside the public folder of my home.blade view at www.mygallery.com
#foreach($items as $item)
<div class="box">
<div class="boxInner">
<img src="{{$item->image}}" alt="{{$item->title}}">
</div>
</div>
#endforeach
By the way this is how my routes file looks like.
Route::get('', array('as'=>'itemshome', 'uses'=>'ItemsController#show_items'));
Route::resource('upload', 'ItemsController');
Route::get('tags/{category?}', array('as'=>'itemstag', 'uses'=>'ItemsController#show_items'));
But when I try to filter results by category (www.mygallery.com/tags/cats) $item->image is trying to reach every image at tags/images/myimage.jpg which of course doesn't exist.
The thing is that I don't want to create a public/tags/images folder, so I wonder how can I explicitly point to the correct folder (public/images) no matter what view/route is making the call.
The problem here is that $item->image is a relative path. So depending on your current URL you will link to different paths.
To generate an absolute URL, use the asset() function:
<img src="{{ asset($item->image) }}" alt="{{$item->title}}">