当前位置: 动力学知识库 > 问答 > 编程问答 >

Using Route::resource or Route::controller in laravel 4

问题描述:

I tried to use

Route::resource('Feed', 'FeedController');<br/>

and

Route::controller('Feed', 'FeedController');

both are not working


This is my route code

route.php

Route::get('/', function()

{

return View::make('pages.home');

});

Route::get('about', function()

{

return View::make('pages.about');

});

Route::resource('Feed', 'FeedController');

Feed.php

<?php

class Feed

extends Eloquent

{

protected $fillable = array('feed', 'title', 'active', 'category');

protected $feeds;

public static $form_rules = array(

'category' => 'required|in:Annoucements,Sports,Events',

'title' => 'required',

'feed' => 'required',

'active' => 'required|between:0,1'

);

public function getParsedFeed($limit = 4)

{

if (is_null($this->feeds)) {

$this->feeds = simplexml_load_file($this->feed);

}

if (!count($this->feed)) {

return array();

}

$output = array();

$content = $this->feeds->channel->item;

foreach (range(0, $limit - 1) as $i) {

$output[] = $content[$i];

}

return $output;

}

}

FeedController.php

<?php

class FeedController extends \BaseController {

/**

* Display a listing of the resource.

*

* @return Response

*/

//The method to show the form to add a new feed

public function create() {

//We load a view directly and return it to be served

return View::make('pages.news');

}

//Processing the form

public function store(){

//Let's first run the validation with all provided input

$validation = Validator::make(Input::all(),Feeds::$form_rules);

//If the validation passes, we add the values to the database and

return to the form

if($validation->passes()) {

//We try to insert a new row with Eloquent

$create = Feeds::create(array('feed'=> Input::get('feed'),

'title' => Input::get('title'),

'active' => Input::get('active'),

'category' => Input::get('category')

));

//We return to the form with success or error message due to state of the

if($create) {

return Redirect::to('feeds/create')

->with('message','The feed added to the databasesuccessfully!');

}

else {

return Redirect::to('feeds/create')

->withInput()

->with('message','The feed could not be added, please try again later!');

}

}

else {

//If the validation does not pass, we return to the form with First error message as flash data

return Redirect::to('feeds/create')

->withInput()

->with('message',$validation->errors()->first());

}

}

}

I need to know where it is wrong I am new to laravel and I am working on learning it by following some tutorials

分享给朋友:
您可能感兴趣的文章:
随机阅读: