How to use javascript(Angular.js) with laravel get php url(asset) - php

I use javascript(Angular.js) with laravel
<aside data-ng-include=" {{ asset('layout/nav') }} " id="nav-container"></aside>
but is error:NotFoundHttpException load no path,
What can be read into the .php file?

Im a little confused on what you are trying to do, but it seems that you are using asset() to link a directory. I would use the laravel function link_to() instead, since it is made to generate links to paths.
Here is the link to the laravel documentation with more information on link_to() and asset():
http://laravel.com/docs/4.2/helpers#urls

Related

Laravel view not rendering correctly

I am trying to add a new view to my laravel project, and it is just dumping the entire content on the page, including my blade code, instead of executing said code. For example, my page in the browser is this:
#extends('user.layouts.app') #section('title', 'New Reminder') #section('content')
New Reminder
#csrf
Title
Content
#endsection
When it should obviously be executing that code, not putting it on the page.
I have tried clearing the routes, and researched around but no dice.
I am calling this view the same way I am calling others in my code - in the controller like this:
return view('user.partials.stat_types.new_type');
Any help or advise is appreciated!
You must have the file name with the extension .blade.php if you want Blade to be used to compile the view. With just .php the PHP engine is used.
Change your view filename to have the .blade.php extension.

Append onto current URL with Twig?

I'm currently making a simple file hosting script using Slim, Twig, and PHP. Right now I'm trying to append onto the current URL using Twig but am not sure how to do this. I've tried /panel/{{ newURL }} but it always just redirects me to /panel/newurl. I need to be able to dynamically update this URL.
For example, if I want to go to /tests on /panel/core/ I need to be able to append that onto the current URL. Does Twig offer a way to do this? Thanks.
Do you use Twig to render your paths? I think your application should always be able to resolve the paths, so also let the application itself render them ;-)
If that would help; you can add the parameters of the current request to the path rendering:
{{ path('yourpath', app.request.query.all|merge({'myparam': 'value'})) }}
you can use the Built-in parameter in twig {{ app.request.uri.path }}
You'll want to ensure that you've included all route and query string parameters in the URL you're appending to.
Here's an example of appending foo=bar to the current URL:
{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge(app.request.query.all)|merge({'foo': 'bar})) }}
I ended up just passing 'url' => $request->getUri()->getPath() in my view parameters. I think this is a pretty decent method because there are other methods you can call on getUri() to get different results depending on what you want to do.

routing in laravel 4.2 loads page but doesn't load styles

when i am using laravel 4 routing as
Route::get("/home", "HomeController#showHome");
it works fine but when i am using routing as
Route::get("/home/about", "HomeController#showHome");
it loads page but doesn't take css and javascript.i tried using named route as
Route::get("/home/about" array(
'as'=>'home',
'uses'=>'HomeController#showHome'));
this doesn't work either, it also loads page without styles.
Use css code as below:
{{ HTML::style('css/css.css'); }}

Use Laravel #include directive with non PHP files?

I have been looking for a way to use Laravels Blade templating engine with non PHP file extensions (instead of file_name.blade.php being able to use file_name.blade.js or file_name.blade.css) to no avail. I found a post that seems to describe how to do exactly this for Laravel 4, however it no longer seems to work in Laravel 5. The reason why I would like to do this is I have a Javascript file that looks something like this:
//JS stuff
#foreach($Model->Values as $Value)
{{ $Value->name . " = " . $Value->content . ";"}}
#endforeach
//More JS stuff
And a blade/php file that looks something like this:
//Blade stuff
<script type="text/javascript">
#include('js');
</script>
And this seems to be the nicest way of passing each value to javascript. Even if there is a nicer way of passing these values to javascript, the reason behind this question is to find if there is a way to parse a non PHP file with blade as I think that could be immensely useful.
I thought View::addExtension('blade.js', 'blade') would work in L5 as well. The method hasn't changed. But do note you'll want the blade engine, not the html one like in the post you linked to. Where to put it is a good question, though. Also, you mentioned your two files have the same name before the extensions - that might screw it up, too.

Laravel routing: How to create a link to a PDF file

I need to generate PDF documents and have them send by email as well as make them reachable by a link.
Sending by email is OK, but I have no idea how to create the link.
Since I use Laravel 4, all links are going through routes.php.
So how do I create a link to a file at a given directory?
Link
will not work, since the route is not known by laravel...
To generate a link to a physical file or directory, that you don't want to run through Laravel's application (e.g. through index.php), use URL::asset().
URL::asset('assets/pdf/file.pdf');
This assumes you've created a physical PDF file on your server that you want to link to. If your PDF file is dynamic and generated/retrieved through your Laravel application, you should use URL::to(), URL::route(), or similar.
Martin Tale is right, but this is another way of accomplishing the same using Laravel's Blade:
{{ link_to('/assets/pdf/file.pdf', 'Link') }}
Create that PDF somewhere in public directory and then create a link to that file like this:
URL::to('path/to/public/directory/file.pdf')
if you are using laravel 4's MAIL feature you can add this to it
$message->attach($pathToFile);
but the .pdf in your public directory under a pdf folder and that will make it:
$message->attach('pdf/mypdffile.pdf');
the same can be for a link which you can add to the email
{{ URL::to('pdf/mypdffile.pdf') }}
You shouldn't need a route to create a link it can be done by blade.
Another way, in a view:
some text
This link will go to public folder.

Categories