I have created a small test-project and wanted to use this:
https://github.com/vluzrmos/collective-html
I have done the same things step by step as in the manual. But I got this error:
Whoops, looks like something went wrong.
In the app.php I enabled this:
$app->withFacades();
$app->withEloquent();
And added the register and alias as given in the manual. Also I changed in the index.php that the requests are working.
My route and my controller are working. If I write only html content the page is fully and correctly shown.
But If I change my blade-template and at this:
{!! $form->open() !!}
{!! $html->asset() !!}
It doesn't work. And the error which I have given before occurs and the page is not shown.
Is the call wrong or should I declare anything in my Controller or in the head of the View?
By the way, the files/library are/is existing and loaded via composer
(Lumen 5.2)
to use this way:
{!! $form->open() !!}
you need to put this on bootstrap/app.php
$app->register('Collective\Html\InjectVarsServiceProvider');
Or you can just use like this:
{!! Form::open(array('url' => '/test')) !!}
Related
I have a master view and depending on the URL and controller, it will load in another subview to a variable called $content, that's the idea.
Currently I am trying with:
return view("master")->with(["content" => view("pages.group")]);
So for example, if the URL is https://example.com/group/1 I am trying to get the subview included on my master template. Currently, it just gets escaped for XSS but I feel like this isn't the right way to do this?
I assume you are trying to display the sub-view content in the follwing way:
{{ $content }}
Change your syntax from {{ }} (Escaped output) to {!! !!} (Non escaped output).
{!! $content !!}
In the end after #lagbox mentioned it, using Laravel sections enabled me to use a master view and extend it when needed. https://laravel.com/docs/6.x/blade#extending-a-layout
I have this weird problem with my Laravel 5.5 version... I created the auth views using
php artisan make:auth
This command created the views controllers and everything I need to lets get stared to work. But I'm having this visualization problem
As you can see on the register view I have this problem.
The real thing is that "{{ any_command }}" is printing the code that its supose to generate instead of interprating like part of the code. But if I use {!! any_command !!} instead it seems to work propertly. What can happend to my laravel is screwed up. It has nothing to be with the artisan auth method, because I tried to create a new form (using laravel collective form helper) and get the same result.
{{ }} will escape all data before printing. So, if you write any HTML tag inside, it will be escaped and printed as is. Just like your example.
{!! !!} will print unescaped data. This will print the tags correctly, but you have to take care where you use it, because someone could inject unwanted data there.
So, in your case, you should use {!! !!}.
Please, refer to this question: What is the difference between {{ }} and {!! !!} in laravel blade files?
Fairly new at Laravel and trying to grasp the store function and routing. I'm getting the following error trying to open a form in Laravel:
Missing required parameters for [Route: {$route->getName()}] [URI: {$route->uri()}].
The issue is because my url is:
/projects/1/documents/create
And I'm opening to:
/projects/1/documents
I'm trying to pass the projects ID but I'm missing something.
Form Call:
{!! Form::open(['route'=>'projects.documents.store', $project->id]) !!}
#include('pages.projects.documents.charter.partials._form', ['submitButtonText'=>'Create Project Charter'])
{!! Form::close() !!}
My Web Route (I'm assuming the issue is here):
// Resource route for Project Document Controller
Route::resource('projects.documents', 'Project\DocumentController');
My DocumentController store function:
public function store(Request $request, Project $project)
{
// Validate the request
}
I'm not sure if there is any other sections of code that are need. The page renders fine without Form::open and $project->id echo's out correctly.
Edit:
I figured out my issue, it was somewhat silly. Just not use to Laravel formatting yet. The route & param needed to be in an array. The correct formatting is:
{!! Form::open(['route'=>array('projects.documents.store', $project->id)]) !!}
This is in my blade file
{!! Html::link(storage_path().'/documents/'.$file->name, $file->name) !!}
This is controller
public function download($file_name){
$file_path = storage_path('documents').'/'.$file_name;
return response()->download($file_path);
}
Route
Route::get('documents/{file}','FilesController#download');
You want to add your exact route to your HTML link instead of the path of the file:
{!! Html::link('/documents/'.$file->name, $file->name) !!}
The proper way of using HTML::link() is like this:
{{ HTML::link(storage_path().'/documents/'.$file->name, 'Download Link')}}
and this would produce the HTML like this:
Download Link
See more about HTML::link()
You can also use route() helper method like this:
Just add a name() method in-front of the route method, as it gives route a common name.
Route::get('documents/{file}','FilesController#download')->name('downloads.link');
HTML should look like this:
Download Link
I've a route:
Route::resource('partner/register', 'PartnerController\Register');
And function index, works. But when I try route to store with:
{!! Form::open(['route'=>'partner/register.store']) !!}
Error:
Route [partner/register.store] not defined.
Why? help please.
PD: I used artisan make:controller PartnerController/Register to create the controller. Because need of create controllers in differents directories
This part is fine I guess as you said you needed it in different directories
Route::resource('partner/register', 'PartnerController\Register');
But to get the store route use
{!! Form::open(['url' => route('partner.register.store')]) !!}
Btw you can see all the current routes with php artisan route:list