I must have missed something...wondering why the parameter isn't getting passed into my route.
My URL ends up looking like
//admin/attendees/%7Battendee%7D/paid
I want the %7Battendees%7D to be replaced with a number
Here's my route and view
Route::post('attendees/{attendee}/paid', array('as' =>'admin.attendees.paid', 'uses'=>'AdminAttendeeController#postPaid'));
{{Form::open(array('class' => 'paid', 'method' => 'POST', 'route' => 'admin.attendees.paid', $attendee->id))}}
What did I do wrong?
This should work:
{{
Form::open(array(
'class' => 'paid',
'method' => 'POST',
'route' => array('admin.attendees.paid', $attendee->id)
))
}}
You can find more details in illuminate/html source code: https://github.com/illuminate/html/blob/master/FormBuilder.php#L799
Related
This is my add.blade.php.
{{ Form::open(array('url' => $id."/item", 'method' => 'post', 'files' => 'true', 'id'=>'add')) }}
{{ Form::text('title'}}
{{Form::submit('Submit')}}
{{Form::close()}}
This is my web.php
Route::resource('{categoryId}/item', 'ItemController');
This is my ItemController.php
public function create($categoryId){
return view('item.add', array('id' => $categoryId));
}
I am trying to add new item to a category. So I click add new and it opens add.blade.php. When I submit from add.blade.php, it is redirecting it to item/create. I think it is because of url in the form of add.blade.php. What is the correct way of doing this? Thanks in advance
I think you should try this:
{{Form::open(['route' => ['item.create', $id],'method' => 'post', 'files' => 'true', 'id'=>'add'])}}
You can try prefix instead of append parameter
Route::group(['prefix' => '{categoryId}'], function()
Route::resource('item', 'ItemController');
});
then use
route('item.create',['1']);
Here in your code just pass parameter and will work like this:
['route' => ['item.create', $id]
your View
{{ Form::open(array('url' => "/item/".$id , 'method' => 'post', 'files' => 'true', 'id'=>'add')) }}
{{ Form::text('title'}}
{{Form::submit('Submit')}}
{{Form::close()}}
your Route
Route::resource('item', 'ItemController');
Route::post('/item/{categoryId}', 'ItemController#create');
your Controller
public function create($categoryId){
$id = $categoryId;
return view('item.add', compact('id'));
}
I'm trying to make an url query string with laravel but this method:
url()->to('categories', ['id' => 1, 'name' => 'cars']);
Returns me:
http://localhost/categories/1/cars
But I need this:
http://localhost/categories?id=1&name=cars
First of all, you'll need to create a named route without parameters:
Route::get('categories', ['as' => 'categories', 'uses' => 'SomeController#showCategories']);
Then use route() helper:
route('categories', ['id' => 1, 'name' => 'cars']);
This will generate:
'/categories?id=1&name=cars'
The answer is:
Route::any(Request::path(), ['as' => Request::path(), 'uses' => 'Extender#xRun']);
I got these routes:
Route::get('prefix/list/{page?}/{size?}', ['as' => 'prefix.list', 'uses' => 'MyController#getList']);
Route::post('prefix/list', ['as' => 'prefix.list', 'uses' => 'MyController#postList']);
When I call link_to_route() like so:
{{ link_to_route('prefix.list', $page, ['page' => $page, 'size' => $size]) }}
It creates this link:
http://my.site/prefix/list?page=5&size=12
But when I remove the post route, it renders correctly this:
http://my.site/prefix/list/5/12
I don't want to change the name of the routes because my system depends on them being the same. How can I solve this?
You could try just changing the order of the routes in your routes file, so that the get one comes last and overrides the post for the purposes of link_to_route().
Yii: 1.1.15
I have a list in my view and behind every row an ajaxLink to delete the row. It works but the browser does not refresh automatically ... with STRG-R it refreshes and the deleted row disappers.
My code:
echo CHtml::ajaxLink('X',
Yii::app()->createUrl('forumkommentar/delete', array("id" => $kommentar->id)), array(
'type' => 'POST',
'data' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
// 'data' => 'js:{"data":' . $kommentar->id . '}',
// 'success' => 'js:function(string){ document.getElementById("' . $kommentar->id . '").remove(); }'
), array(
'class' => 'btn btn-danger small-btn',
'confirm' => 'Are you sure?', //Confirmation
));
I think I need the two commented lines above to refresh the window - but it does not work.
My questions:
How can I combine the two "data"-lines? (line 4 and 5)
What is wrong in my code - or how would you do it?
Firs, you are making ajax request with POST type, so you can't use url parameters, because url parameters are GET parameters. Therefore I think this can be helpful:
echo CHtml::ajaxLink('X',
Yii::app()->createUrl('forumkommentar/delete'), array(
'type' => 'POST',
'data' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken, "kommentar" => $kommentar->id),
//'success' => 'js:function(string){ document.getElementById("' . $kommentar->id . '").remove(); }'
), array(
'class' => 'btn btn-danger small-btn',
'confirm' => 'Are you sure?', //Confirmation
));
Now, you can access $_POST['kommentar'] in the actionDelete() of ForumkommentarController.
i am receving this error in laravel 4.2.*
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
when i am updating a record.
// Routing
Route::get('projects/edit/{slug}', array('as' => 'projects.edit', 'uses' => 'ProjectsController#edit'));
Route::put('projects/update?{slug}', array('as' => 'projects.update', 'uses' => 'ProjectsController#update'));
// Controller
public function update($slug){
$pr = $this->project->whereSlug($slug)->first();
$this->project->fill(Input::all());
$this->project->save();
}
// Form
{{ Form::model($project, ['method' => 'PATCH', 'route' => ['projects.update', project->slug ],'files' => true]) }}
{{ Form::close() }}
// URL
pms2.dev/projects/update?slug
hope someone know, why i am facing this.
try to replace your routing as follow
Route::patch('projects/update', array('as' => 'projects.update', 'uses' => 'ProjectsController#update'));
Since your form's method is set to PATCH then your route should also be defined with the same verb.
Route::patch('projects/update?{slug}', array('as' => 'projects.update', 'uses' => 'ProjectsController#update'));
http://laravel.com/api/4.2/Illuminate/Routing/Router.html#method_patch
However i think POST is the more appropriate method here.