Routing in laravel 5 with resource - php

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

Related

How to use controller methods in laravel 8 with collective html?

This is code from one of my views, create.blade.php
Error: Action PetsController#store not defined.
I think this has something to do with Laravel 8 different way to call controller methods.
The controller is PetsController and it was created to be a CRUD (php artisan make:controller PetsController --resource)
using php artisan route:list it says that i should use "App\Http\Controllers\PetsController#store" in 'action', but isn't there a better way to do this?
#extends('layouts.app')
#section('content')
{!! Form::open([
'method'=>'post', 'action'=>'PetsController#store'
]) !!}
#endsection

laravel 6.5 shows an edit url with a question mark

In laravel 6.5 when using the route helper function and creating an edit link the output that i get is myurl/myroute?id=1 where before it was myurl/myroute/1/edit. How can i go back to the previous state?
this is my code, my routes are named.
Edit
If you use a route resource:
Route::resource('project', 'ProjectsController);
Then it uses {project} as the model binding so instead of id you should pass project.
{{ route('project.edit', $project) }}
Should work just fine and replace the wild card with the id of the model.
Running php artisan route:list will give you exactly the name of the parameter expected in the route :)

Laravel blade "{{ command }}" not working correctly

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?

Laravel 5 GET inside controller?

I use Laravel5 and i cant understand why postProcess or getProcess not works?
Example::
html page:
{{ Form::open(array('url' => 'portfolio/process')) }}
{{ Form::submit() }}
{{ Form::close() }}
route:
Route::resource('portfolio','PortfolioController');
controller:
public function postProcess (){
return 'Text!';
}
Every time i get error:
MethodNotAllowedHttpException in RouteCollection.php line 218:
It doesn't work because Route::resource doesn't build these routes and you need to explicitly define them:
Route::post('portfolio/process', 'PortfolioController#postProcess');
I think you need to check your route list:
Run this command php artisan route:list in terminal and check your route.
Hope this work for you!

Lumen Collective-HTML Form

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

Categories