为什么auth-register路由为空,而自定义路由显示另一个控制器错误



我尝试创建了两种不同的注册表格。

第一次尝试是Auth::routes();登录表单和路线,但注册页面显示空白页面。如果我尝试了Auth::routes(['register' => false]);,那么至少会显示404 page

然后我尝试使用自定义路线:

Route::group(['namespace' => 'Auth', 'prefix' => 'partner'], function () {
Route::get('login', 'LoginController@showLoginForm')->name('login');
Route::post('login', 'LoginController@login');
Route::get('register', 'RegisterController@showRegistrationForm')->name('register');
Route::post('register', 'RegisterController@register');
});

两个控制器都显示前控制器错误线665

我的Auth注册控制器:

namespace AppHttpControllersAuth;
use AppHttpControllersController;
use IlluminateHttpRequest;
use AppUser;
use AppCompany;
use Hash;
class RegisterController extends Controller
{
public function __construct()
{
parent::__construct();
view()->share('pageTitle', __('email.registerAccount'));
}
public function showRegistrationForm()
{
return view('auth.register');
}
public function register(Request $request)
{
$request->validate([
'first_name' => 'required|string|max:255',
'last_name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'phone', 'required|integer|max:255',
'password' => 'required|string|min:8|confirmed',
'business_type' => 'required'
]);
$user = new User();
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->calling_code = $request->calling_code;
$user->mobile = $request->mobile;
$user->email = $request->email;
$user->password = $request->password;
if ($request->hasFile('image')) {
$user->image = Files::upload($request->image,'avatar');
}
$user->save();
$company = new Company();
$company->owner_id = $user->id;
$company->type = $request->business_type;
$company->save();
return redirect('login');
}
}

我的任务是为客户和合作伙伴创建注册表,所以我想我会使用相同的授权控制器,但使用不同的功能。。

但我不明白为什么它显示前控制器错误:

"Trying to get property 'name' of non-object" - line 665

如果我使用的是头版,就不会有任何错误。它只显示在注册表中。

665行:

public function serviceDetail(Request $request, $categorySlug, $serviceSlug)
{
$service = BusinessService::where('slug', $serviceSlug)->first();

$products = json_decode($request->cookie('products'), true) ?: [];
$reqProduct = array_filter($products, function ($product) use ($service) {
return $product['serviceName'] == $service->name; //Line 665
});

return view('front.service_detail', compact('service', 'reqProduct'));
}
$service = BusinessService::where('slug', $serviceSlug)->first();

返回null。

确保BusinessService中有数据,'slug' === $ serviceSlug时有数据无论如何,你必须在没有从数据库返回数据的地方开车

相关内容

  • 没有找到相关文章

最新更新