Created
March 5, 2013 11:39
-
-
Save rubemlrm/5089726 to your computer and use it in GitHub Desktop.
model for articles table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Dojo\Models; | |
| use \Laravel\Database\Eloquent\Model as Eloquent; | |
| class Article extends Eloquent{ | |
| public static $timestamps = true; | |
| public function author(){ | |
| return $this->belongs_to('Dojo\Models\User','author_id'); | |
| } | |
| public function tags(){ | |
| return $this->has_many_and_belongs_to('Dojo\Models\Tag'); | |
| } | |
| public static function get_order($field,$value,$order){ | |
| $articles = Article::order_by($order,'asc')->where($field,'=',$value)->get(); | |
| return $articles; | |
| } | |
| public static function get_query($field,$value){ | |
| $articles = Article::where($field,'=',$value)->get(); | |
| return $articles; | |
| } | |
| public static function get_totals($field,$value){ | |
| $total = Article::where($field,'=',$value)->count(); | |
| return $total ; | |
| } | |
| public static function post_update($field,$value,$id){ | |
| $article = Article::find($id); | |
| $article->$field = $value; | |
| $article->save(); | |
| } | |
| public static function post_delete($id){ | |
| $article = Article::with('author')->find($id); | |
| $article->delete(); | |
| } | |
| public static function get_search($keyword){ | |
| $article = static::where('title','LIKE', '%'.$keyword.'%')->paginate(5); | |
| return $article; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| Route::any('/(:bundle)/logout','Dojo::login@logout'); | |
| Route::any('/(:bundle)/login', array('as'=>'dojo::login','uses'=>'Dojo::login@index')); | |
| Route::any('/(:bundle)/users',array('as'=>'dojo::index_user','uses'=>'Dojo::user@index')); | |
| Route::get('/(:bundle)/users/edit/(:any)',array('as'=>'dojo::edit_user','uses'=>'Dojo::user@edit')); | |
| Route::get('/(:bundle)/users/view/(:any)',array('as'=>'dojo::view_user','uses'=>'Dojo::user@view')); | |
| Route::put('/(:bundle)/users/edit/update',array('as'=>'dojo::update_user','uses'=>'Dojo::user@update')); | |
| Route::any('/(:bundle)/users/delete/(:any)',array('as'=>'dojo::delete_user','uses'=>'Dojo::user@erase')); | |
| //articles routes | |
| Route::any('/(:bundle)/articles/new/redactor',array('as'=>'dojo::new_image','uses'=>'Dojo::article@redactorupload')); | |
| Route::get('/(:bundle)/articles/edit/(:any)',array('as'=>'dojo::edit_article','uses'=>'Dojo::article@edit')); | |
| Route::post('/(:bundle)/articles/edit/update',array('as'=>'dojo::updated_article','uses'=>'Dojo::article@edit')); | |
| Route::put('/(:bundle)/articles/quick_edit/update',array('as'=>'dojo::update_mass','uses'=>'Dojo::article@update')); | |
| Route::any('/(:bundle)/articles/delete/(:any)',array('as'=>'dojo::delete_article','uses'=>'Dojo::article@erase')); | |
| Route::any('/(:bundle)/articles/new',array('as'=>'dojo::new_article','uses'=>'Dojo::article@new')); | |
| Route::any('/(:bundle)/articles/(:any?)/(:any?)/(:any?)',array('as'=>'dojo::index_article','uses'=>'Dojo::article@index')); | |
| Route::post('/(:bundle)/articles/search',array('uses'=>'Dojo::article@search')); | |
| Route::get('/(:bundle)/articles/results/(:all)',array('as'=>'dojo::results_article','uses'=>'Dojo::article@results')); | |
| //projects routes | |
| Route::any('/(:bundle)/projects/new/redactor',array('as'=>'dojo::new_image_project','uses'=>'Dojo::project@redactorupload')); | |
| Route::get('/(:bundle)/projects/edit/(:any)',array('as'=>'dojo::edit_project','uses'=>'Dojo::project@edit')); | |
| Route::post('/(:bundle)/projects/edit/update',array('as'=>'dojo::update_project','uses'=>'Dojo::project@edit')); | |
| Route::any('/(:bundle)/projects/delete/(:any)',array('as'=>'dojo::delete_project','uses'=>'Dojo::project@erase')); | |
| Route::any('/(:bundle)/projects/new',array('as'=>'dojo::new_project','uses'=>'Dojo::project@new')); | |
| Route::any('/(:bundle)/projects/(:any?)/(:any?)/(:any?)',array('as'=>'dojo::index_project','uses'=>'Dojo::project@index')); | |
| Route::post('/(:bundle)/projects/search',array('uses'=>'Dojo::project@search')); | |
| Route::get('/(:bundle)/projects/results/(:all)',array('as'=>'dojo::results_project','uses'=>'Dojo::project@results')); | |
| Route::put('/(:bundle)/projects/edit/update',array('as'=>'dojo::update_project','uses'=>'Dojo::project@update')); | |
| //settings | |
| Route::any('/(:bundle)/settings',array('uses'=>'Dojo::setting@index')); | |
| Route::any('/(:bundle)/settings/social',array('uses'=>'Dojo::setting@social')); | |
| Route::controller(Controller::detect('dojo')); | |
| Route::filter('auth',function(){ | |
| if (Auth::guest()) return Redirect::to(URL::to_action('dojo::login')); | |
| }); | |
| Route::filter('csrf', function() | |
| { | |
| if (Request::forged()) return Response::error('500'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment