/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show(JobCategory $category)
 {
     $jobs = $category->jobs()->latest('published_at')->published()->get();
     return view('admin.jobs.index', compact('jobs'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(JobFormRequest $request, $id)
 {
     $job = $this->jobs->whereId($id)->first();
     $job->categories()->detach();
     $job->tags()->detach();
     $job->name = $request->get('name');
     $job->purpose = $request->get('purpose');
     $job->experience = $request->get('experience');
     $job->content = $request->get('content');
     $job->start_range = $request->get('start_range');
     $job->end_range = $request->get('end_range');
     $job->slug = str_slug($request->get('slug'));
     $job->published = $request->input('published') === 'on' ? true : false;
     $job->published_at = $request->input('published_at');
     $job->expiration_at = $request->input('expiration_at');
     $job->update();
     foreach ($request->categories as $index => $category_id) {
         $category = JobCategory::whereId($category_id)->first();
         $job->assignCategory($category);
     }
     foreach ($request->tags as $index => $tag_id) {
         $tag = JobTag::whereId($tag_id)->first();
         $job->assignTag($tag);
     }
     return \Redirect::route('admin.jobs.index')->with('flash_message', 'Job added!');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // validate
     // read more on validation at http://laravel.com/docs/validation
     $rules = array('judul' => 'required', 'deskripsi' => 'required', 'upah_max' => 'required|numeric', 'upah_min' => 'required|numeric', 'kategori' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return Redirect::to('job/' . $id . '/edit')->withErrors($validator)->withInput(Input::except('password'));
         // TODO: Check
     } else {
         // store
         $updated_job = Job::find($id);
         $updated_job->judul = Input::get('judul');
         $updated_job->deskripsi = Input::get('deskripsi');
         $updated_job->upah_max = Input::get('upah_max');
         $updated_job->upah_min = Input::get('upah_min');
         $updated_job->save();
         $updated_category = JobCategory::where('job_id', $id)->first();
         $updated_category->category_id = Input::get('kategori');
         $updated_category->save();
         // redirect
         Session::flash('message', 'Successfully updated job!');
         return Redirect::to('job/' . $id);
     }
 }
<?php

Route::group(['namespace' => 'App\\Http\\Controllers', 'middleware' => ['web', 'throttle']], function () {
    //'prefix'=>'api/v1',
    Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'admin'], 'namespace' => 'Admin'], function () {
        Route::resource('job_tags', 'JobTagController', ['only' => ['index', 'show', 'create', 'store', 'edit', 'update', 'destroy']]);
        Route::resource('jobs', 'JobController', ['only' => ['index', 'show', 'create', 'store', 'edit', 'update', 'destroy']]);
        Route::resource('job_categories', 'JobCategoryController', ['only' => ['index', 'show', 'create', 'store', 'edit', 'update', 'destroy']]);
        Route::post('jobs/{jobs}/upload', ['as' => 'admin.jobs.upload', 'uses' => 'JobController@upload']);
        Route::get('jobs/{jobs}/image-upload', ['as' => 'admin.jobs.image-upload', 'uses' => 'JobController@getUpload']);
    });
});
View::composer('*', function ($view) {
    $job_categories = \App\JobCategory::where('parent_id', '=', 0)->get();
    //
    if (!$job_categories) {
        $job_categories = [];
    }
    $job_tags = \App\JobTag::with('jobs')->get();
    if (!$job_tags) {
        $job_tags = [];
    }
    $view->with(compact('job_categories', 'job_tags'));
});