Advertisement
Guest User

Controller Category

a guest
Apr 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.83 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Admin;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use App\Category;
  8. use Carbon\Carbon;
  9. use Response;
  10. use App\Http\Requests\StoreCategoryRequest;
  11.  
  12. use Illuminate\Support\Facades\Validator;
  13. use Illuminate\Support\Facades\View;
  14.  
  15. use Illuminate\Support\Facades\Input;
  16. use Illuminate\Support\Facades\Redirect;
  17. use DateTime;
  18. use Intervention\Image\Facades\Image as Image;
  19. use Illuminate\Support\Facades\Session;
  20.  
  21. use JsValidator;
  22. class CategoryController extends Controller
  23. {
  24.    public function __construct()
  25.    {
  26.        $this->middleware('auth:admin');
  27.     }
  28.    
  29.    
  30.         protected $validationRules=[
  31.                 'name' => 'required',
  32.                 'name2' => 'required',
  33.     ];
  34.     /**
  35.      * Display a listing of the resource.
  36.      *
  37.      * @return \Illuminate\Http\Response
  38.      */
  39.     public function index(Request $request)
  40.     {
  41.        
  42.         $categories = Category::select('updated_at','created_at','active','description','slug','name','id')->where('active', 1)->where('translation_lang',trans('label.Language_code'))
  43.                ->orderBy('name', 'id')
  44.                ->take(10)
  45.                ->get();
  46.         return view('admin.category.index')->with(compact('categories'));
  47.     }
  48.  
  49.     /**
  50.      * Show the form for creating a new resource.
  51.      *
  52.      * @return \Illuminate\Http\Response
  53.      */
  54.     public function create(Category $category)
  55.     {
  56.    
  57.        
  58.         return view('admin.category.create');
  59.     }
  60.  
  61.     /**
  62.      * Store a newly created resource in storage.
  63.      *
  64.      * @param  \Illuminate\Http\Request  $request
  65.      * @return \Illuminate\Http\Response
  66.      */
  67.     public function store(Request $request)
  68.     {
  69.         //
  70.         $validator=Validator::make($request->all(),[
  71.             'name' => 'required|max:255',
  72.             'name2' => 'required|max:255', 
  73.         ]);
  74.         if($validator->fails()){
  75.             return redirect(route('admin.category.create'))
  76.                 ->withErrors($validator)
  77.                 ->withInput();
  78.         }
  79.    
  80.         $post = Input::All();
  81.         //if(!empty($post['name']))
  82.             //{
  83.         $id = \DB::table('categories')->insertGetId([
  84.             'translation_lang'=>'id',
  85.             'translation_of' => NULL,                      
  86.             'parent_id' => 0,
  87.             'name'=>ucfirst($post['name']),
  88.             'slug'=>strtolower($post['name']),
  89.             'description'=>ucfirst($post['name']), 
  90.             'depth'=>1,
  91.             'type'=>'Event',
  92.             'active'=>1,   
  93.             'created_at' => \Carbon\Carbon::now()->toDateTimeString()
  94.             ]);
  95.             //}
  96.            
  97.         //if(!empty($post['name2']))
  98.             //{
  99.         \DB::table('categories')->insert([
  100.             'translation_lang'=>'en',
  101.             'translation_of' => $id,                       
  102.             'parent_id' => 0,
  103.             'name'=>ucfirst($post['name2']),
  104.             'slug'=>strtolower($post['name2']),
  105.             'description'=>ucfirst($post['name2']),
  106.             'depth'=>1,
  107.             'type'=>'Event',
  108.             'active'=>1,   
  109.             'created_at' => \Carbon\Carbon::now()->toDateTimeString()
  110.             ]);
  111.             //}        
  112.            
  113.        
  114.        // Session::flash('flash_message', 'Ticket added!');
  115.         return redirect(route('admin.category.index'));            
  116.     }
  117.  
  118.     /**
  119.      * Display the specified resource.
  120.      *
  121.      * @param  int  $id
  122.      * @return \Illuminate\Http\Response
  123.      */
  124.     public function show($id)
  125.     {
  126.         //
  127.     }
  128.  
  129.     /**
  130.      * Show the form for editing the specified resource.
  131.      *
  132.      * @param  int  $id
  133.      * @return \Illuminate\Http\Response
  134.      */
  135.     public function edit($id)
  136.     {
  137.         //
  138.     }
  139.  
  140.     /**
  141.      * Update the specified resource in storage.
  142.      *
  143.      * @param  \Illuminate\Http\Request  $request
  144.      * @param  int  $id
  145.      * @return \Illuminate\Http\Response
  146.      */
  147.     public function update(Request $request, $id)
  148.     {
  149.         //
  150.     }
  151.  
  152.     /**
  153.      * Remove the specified resource from storage.
  154.      *
  155.      * @param  int  $id
  156.      * @return \Illuminate\Http\Response
  157.      */
  158.     public function destroy($id)
  159.     {
  160.         //
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement