以下是AdminController.php的控制器代码
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Schema;
use Illuminate\Database\Schema\Blueprint;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Session;
use Redirect;
use Response;
use App\KGB;
class AdminController extends Controller
{
public function add_kgb()
{
$kgb_type = Input::get('kgb_type');
$kgb_price = Input::get('kgb_price');
$region_id = Input::get('region_id');
$brand_id = Input::get('brand_id');
$count = KGB::count();
$kgb_id = "KGB".sprintf("%05d", ($count+1));
$add_kgb = new KGB;
$add_kgb->kgb_id = $kgb_id;
$add_kgb->kgb_type = $kgb_type;
$add_kgb->kgb_price = $kgb_price;
$add_kgb->region_id = $region_id;
$add_kgb->brand_id = $brand_id;
$add_kgb->flag = '1';
$add_kgb->save();
Session::flash('kgb_success','Successfully Added KG Billing!');
return Redirect::to('kgb');
}
public function edit_kgb()
{
$kgb_type = Input::get('kgb_type');
$kgb_price = Input::get('kgb_price');
$region_id = Input::get('region_id');
$brand_id = Input::get('brand_id');
$kgb_id = Input::get('kgb_id');
KGB::where('kgb_id', $kgb_id)->update(array('kgb_type' => $kgb_type, 'kgb_price' => $kgb_price, 'region_id' => $region_id, 'brand_id' => $brand_id));
Session::flash('kgb_success_edit','Successfully Edited KG Billing!');
return Redirect::to('kgb');
}
public function kgb_status($id)
{
$status = KGB::where('id',$id)->pluck('status');
if($status=='0')
KGB::where('id',$id)->update(array('status' => '1'));
else
KGB::where('id',$id)->update(array('status' => '0'));
Session::flash('kgb_success_status','Successfully Edited KG Billing!');
return Redirect::to('kgb');
}
}
这是我的基本控制器代码
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
abstract class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
}
这是我的路线代码
Route::get('kgb', function () {
return view('admin.kgb');
});
Route::post('add_kgb', 'AdminController@add_kgb');
Route::post('edit_kgb', 'AdminController@edit_kgb');
Route::get('kgb_status/{id}', 'AdminController@kgb_status');
这个是我的模特
namespace App;
use Illuminate\Database\Eloquent\Model;
class KGB extends Model
{
protected $table = 'kg_billing';
}
直到现在我的所有控制器和路由都在工作,但现在这个方法引发了错误。请帮帮我