数据没有进入资源控制器层

时间:2018-04-18 09:30:51

标签: laravel laravel-5

我无法在资源控制器中接收任何数据,当我调用edit方法时,它会从模型中提供数据 以下是我在路线中的代码

 Route::resources([
    'faq' => 'Admin\AdminFaqController',
    'post' => 'Admin\AdminPostController',
    'investor' => 'Admin\AdminInvestorController',
    'partner' => 'Admin\AdminPartnerController',
    'news' => 'Admin\AdminNewsController',
    'biller' => 'Admin\AdminBillerController'
]);
AdminBillerController中的

代码

<?php

namespace App\Http\Controllers\Admin;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Auth;
class AdminBillerController extends Controller
{

public function __construct()
{
  $this->middleware('auth:admin');
}

public function index()
{
try {
  $billers = User::role('billers')->get()->toArray();
  return view('admin.billers.index',['data'=>$billers]);
}
catch (Exception $e) {
  $err= $e->getMessage();
  return response()->json(['data'=>$err,'error'=>true,'success'=>false]);
  }
}

public function create()
{
    return view('admin.billers.create');
}


public function store(Request $request)
{
   //dd($request->all()); 
   if ($request->hasFile('billers_logo')) {
     $file = $request->file('billers_logo')->store('uploads/billers');
 }
   // dd($file);
 $requestData=array(
    'user_firstname'=>$request->billers_name,
    'email'=>$request->email,
    'user_username'=>$request->billers_username,
    'user_phone'=>$request->billers_phone,
);
 $validator = Validator::make($requestData, [
    'user_firstname' => 'required|string|max:60',
    'email' => 'required|email|max:100|unique:users,email',
    'user_username' => 'required|max:100|unique:users,user_username',
    'user_phone' => 'required|string|max:35|unique:users,user_phone',

]);
 if ($validator->fails()) {
        //dd($validator->errors());
    return view('admin.billers.create',['error'=>$validator->errors()]);
}

try{
    $data = $request->all();
    $user=User::create([
        'user_firstname' => $data['billers_name'],
        'user_username' => $data['billers_username'],
        'email' => $data['email'],
        'user_phone' => $data['billers_phone'],
        'user_picture'=>$file,
    ]);
    $user->assignRole('billers');
} 
catch (Exception $e) {
  $err= $e->getMessage();
  return redirect('billers/create')
  ->withErrors($validator)
  ->withInput();
      //return view('admin.billers.create',['error'=>$validator->errors()], 
401);
  }


}


public function show(User $user)
{
    //
}


public function edit(User $user)
{   
    dd($user);
    //$date(format)ata=User::where('user_id',$user->id)->get();
    return view('admin.billers.edit',['data'=>$user]);
}


public function update(Request $request, User $user)
{
    //
}


public function destroy(User $user)
{
    //
}

}

在编辑或任何其他功能,它从用户模型返回我的数据我不知道是什么错误

如果您想从我这边获得任何意见,请告诉我

0 个答案:

没有答案