Laravel 5 includes without blade - laravel

I would like to include a file on my index page. In php I use something like include('include/header.php');
or in larvel 4 I used include(app_path().'/views/includes/header.php');
My question is...How is it done in Laravel 5 since the whole framework has changed folder structures and what not? It seems that app_path() is not longer valid. Also, I do not want to leverage blade syntax. Does anyone have an idea on this?

Use base_path because the views are not outside off the app directory. Also you can pass the path to the function, no need for string concatenation
include(base_path('resources/views/includes/header.php'));

Try it like this:
include(app_path().'/../resources/views/includes/header.php');

Related

Shorten directive in laravel

I'm trying to use laravel component and slot.
As I'm using blade templates under components folder, my blade syntax is something like this
#component('components.button',['data'=>$data])
#endcomponent
Here, every times I call it, I have to write the word "component" multiple times.
can I shorten it as below?
#component('button',['data'=>$data])
If yes, how can I achieve it?
You must use of Aliasing Components functionality
If your Blade components are stored in a sub-directory, you may wish to alias them for easier access. For example, imagine a Blade component that is stored at resources/views/components/alert.blade.php. You may use the component method to alias the component from components.alert to alert. Typically, this should be done in the boot method of your AppServiceProvider:
Blade::component('components.alert', 'alert');
Referense

Getting the URL details - Laravel

I am working on a Laravel project, where I want to toggle partials based on the URL data like
foo.bar.com/#itemone/create
foo.bar.com/#itemone/view
Basically, I want to pass whether it is create or view to the partials like this
#include('partials.layouts._core_activity_header',['layout_type' => "create"])
How do I achieve this? Any help would be appreciated.
you can use the route name
Route::getCurrentRoute()->getName()
this will return the route alias

Sorry, the page you are looking for could not be found without showing any error : Laravel 5.5

Newly installed Laravel 5.5 showing Sorry, the page you are looking for could not be found. without any error . Please see the screenshot :
I think its not even looks into routes file, this is my routes.php and htaccess
What will be the reason for this ?
All your WEB routes will be located in the file:
routes\web.php
Register your routes there.
Order
Pay attention to routes order, it's really important (fooled me so many times to be honest).
Because Laravel goes through list of routes top to bottom until it finds the first match, as a rule of thumb, try to define routes with no parametres first then routes with parameters in your route file (web/api).
Example: (based on Radical's answer)
Route::get('/blog/{id}', 'BlogController#show');
Route::get('/blog/comments', 'BlogController#comments');
In this case, Route::get('/blog/{id}', 'BlogController#show'); comes first so it would be selected. Even when what you really want is Route::get('/blog/comments', 'BlogController#comments');
My two cents :)
I ran into this issue when findOrFail method failed in the Controller method.
Ensure that your register.blade.php is in the resources/views directory and remove the trailing slash from the URL you are assigning to this view.
Sometimes the error messages in the storage/logs/laravel.log log file (if you have the default configuration) can help as well.
There are a lot of reasons why this won't work
Probably the route was written well eg: Route::get('/boost/{type}/{{type_id}}', ['uses' => 'RequestController#getBoosted', 'as'=>'boosts/{{type}}/{{type_id}}']);
when it is meant to be like this: Route::get('/boost/{type}/{type_id}', ['uses' => 'RequestController#getBoosted', 'as'=>'boosts/{type}/{type_id}']);
Looking at the two above code the second route is correct because of the curly brackets are one instead of two
Probably you will be needing to clear your cache which happens at rare occasions
Probably the developer in question did not put the links properly at there controllers Return view('site.block')
you must make sure that the page that is referenced is at the correct location
I think you can use this commands:
php artisan config:cache
php artisan view:clear
these commands use and I hope your error solve

Laravel 4 : Embedding blade template tags

I have saved some template tags in database, i want to process them when they are fetched from database. For instance, i have included this file in content and saved it in DB. When i fetch it just prints out in plain text.
#include('frontend.map')
Is there any way to process it? I know .blade extension is required for the engine to parse but how do we deal when the template tags and variables are saved in DB?
Blade wont support that.
What your asking is to allow Blades commands to be interpreted from supplied variables. It would actually be a massive security risk.
You'll need to have another solution that does not involve the use of Blade function calls inside your variables (database).
Perhaps have your view load a different template based upon the variable that you need?

Trouble with Codeigniter Routes involving a query

I'm having a little trouble with a CodeIgniter route when there is a query (stuff after the ?) in the URI. I know it is good practice to replace queries with routes in CI, but I'm importing in a premade messageboard that already does everything with queries. This is my route:
$route['messageboard/:any'] = "messageboard/index";
Any in this case refers to a script name. So if it's messageboard/admin.php, I have it load a view that loads my premade messageboard's script "admin.php". It's working just fine if I do messageboard/admin.php. It does fine if I do messageboard/admin.php?. If I put a parameter into the query, however, the route won't correctly send the user to the messageboard controller, and instead sends them to a 404. Does anyone have any ideas on how to make this work? I would be eternally grateful. Thanks!
Okay guys, I solved it. I needed to change three things. The first was mtvee's suggestion, which lets it read query strings. The second one you're going to want to change the $config['permitted_uri_chars'] in the config file to include an equals sign, since it starts off disabled and all query strings will be of the for ?a=34 or something like that. The third is you need to go to $config['uri_protocol'] and change it from AUTO to PATH_INFO. Once I did those, it worked.
I'm sure the syntax is:
$route['messageboard/(:any)'] = "messageboard/index"; //<-- notice brackets
and not
$route['messageboard/:any'] = "messageboard/index";
I believe CI doesn't do GET out of the box. Check out Enabling Query Strings here http://ellislab.com/codeigniter/user-guide/general/urls.html

Resources