2013-12-19 2 views
0

Я не могу понять, что мне не хватает. Я пытаюсь передать форму методу контроллера по именованному маршруту со всеми его входами и image-> id в качестве параметра. Я продолжаю получать notfoundhttpexception. Если я удалю/{$ id} из объявления маршрута, я получаю отсутствующий параметр для ошибки действия контроллера. Вот код:Не удается передать параметр по именованному маршруту

Маршрут

Route::post('images/toalbum/{$id}', array('as' => 'imgToAlbum', 'uses' => '[email protected]')); 

routes.php

<?php 

/* 
|-------------------------------------------------------------------------- 
| Application Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register all of the routes for an application. 
| It's a breeze. Simply tell Laravel the URIs it should respond to 
| and give it the Closure to execute when that URI is requested. 
| 
*/ 


Route::get('/', array('as' => 'home', function() 
{ 
    return View::make('layouts.default'); 
})); 

Route::get('users/login', '[email protected]'); 
Route::get('users/logout', '[email protected]'); 

Route::post('users/login', '[email protected]'); 

Route::resource('users', 'UsersController'); 

Route::resource('images', 'ImagesController'); 
//routes related to images 
    Route::post('images/toalbum/{$id}', array('as' => 'imgToAlbum', 'uses' => '[email protected]')); 

Route::resource('videos', 'VideosController'); 

Route::resource('albums', 'AlbumsController'); 

мнение, что это представление в виде:

@extends('layouts.default') 

    @section('content') 
    <?php 
    $albumarray = array(null => ''); 
    ?> 

    {{ HTML::image($image['s3Url'], $image['altText']) }} 
    <p> 
     Title:{{ $image['caption'] }}</br> 
     Alt-Text: {{ $image['altText'] }}</br> 
     Description: {{ $image['description'] }}</br> 
    </p> 

    {{ Form::open(array('route' => array('imgToAlbum', $image['id']), 'method' => 'post')); }} 


    @foreach ($albums as $album) 
     <?php 
     array_push ($albumarray, array($album['id'] => $album['caption'])); 
     ?> 
    @endforeach 


    {{ Form::label('Add image to album?') }} 
    {{ Form::select('album', $albumarray) }}</br> 



    {{ Form::submit('Add to Album')}} 

    {{Form::close();}} 

    <?php 
     echo $albums; 
    ?> 

    @stop 

    @section('footer') 

    @stop 

контроллер:

<?php 

class ImagesController extends BaseController 
{ 
    protected $image; 

    public function __construct(Image $image) 
    { 
     $this->image = $image; 
    } 


    // add image to album 

    public function addImageToAlbums($id) 
    { 
     dd($album = Input::all()); 

     $image = $this->where('id', '=', $id); 

     $image->albumId = $album; 

     $this->image->save(); 

     /*return Redirect::route('image.show', $this->image->id) 
      ->with('message', 'Your image was added to the album');*/ 
    } 
} 

ответ

1

Возможно, это поможет кому-то в будущем, поэтому вместо удаления здесь будет ответ. удаление $ from images/toalbum/{$ id} в объявлении маршрута разрешило проблему.

Смежные вопросы