页面在 laravel 中的同一页面上重定向,在网络选项卡中找到 302?
Page redirects on same page in laravel getting 302 found in network tab?
我正在使用 xampp 服务器为我的项目使用来自 envato market 的 larapay 模板。我将分享我现在正在处理的代码。实际上我卡在了安装部分。我能够完成我的安装部分,它创建了 db 和所有,它向我显示了成功的消息,但它没有在登录页面上重定向。它重定向到同一安装页面。
但实际上又去安装了
我的web.php:
Route::resource('/install', 'AccController',['only' => ['index', 'store']]);
AccController.php :
public function store(AccRequest $request){
$link = @mysqli_connect($request->input('hostname'), $request->input('mysql_username'), $request->input('mysql_password'));
if (!$link)
return response()->json(['message' => trans('messages.connection_not_established'), 'status' => 'error']);
mysqli_select_db($link,$request->input('mysql_database'));
$count_table_query = mysqli_query($link,"show tables");
$count_table = mysqli_num_rows($count_table_query);
if (!is_file('../database/database.sql'))
return response()->json(['message' => trans('messages.database_file_not_found'), 'status' => 'error']);
if($count_table)
return response()->json(['message' => trans('messages.table_already_exists'), 'status' => 'error']);
$templine = '';
$lines = file('../database/database.sql');
foreach ($lines as $line)
{
if (substr($line, 0, 2) == '--' || $line == '')
continue;
$templine .= $line;
if (substr(trim($line), -1, 1) == ';')
{
mysqli_query($link,$templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
$templine = '';
}
}
$username = $request->input('username');
$password = bcrypt($request->input('password'));
$email = $request->input('email');
$first_name = $request->input('first_name');
$last_name = $request->input('last_name');
$default_role = config('constant.default_role');
$default_customer_role = config('constant.default_customer_role');
$default_staff_role = config('constant.default_staff_role');
$default_department = config('constant.default_department');
$default_designation = config('constant.default_designation');
mysqli_query($link, "insert into roles(name,is_hidden,is_default) values('$default_role','1','0'),('$default_customer_role','0','1'),('$default_staff_role','0','0')");
mysqli_query($link, "insert into departments(name,is_hidden) values('$default_department','1')");
mysqli_query($link, "insert into designations(department_id,name,is_hidden) values('1','$default_designation',1)");
mysqli_query($link, "insert into users(email,username,password,is_hidden,status) values('$email','$username','$password','1','active') ");
mysqli_query($link, "insert into profiles(user_id,first_name,last_name,designation_id) values('1','$first_name','$last_name','1') ");
mysqli_query($link, "insert into role_user(user_id,role_id) values('1','1') ");
envu([
'DB_HOST' => $request->input('hostname'),
'DB_NAME' => $request->input('mysql_database'),
'DB_USERNAME' => $request->input('mysql_username'),
'DB_PASSWORD' => $request->input('mysql_password')
]);
//complete($purchase_code);
$this->logActivity(['module' => 'application','activity' => 'installed']);
return response()->json(['message' => trans('messages.installation').' '.trans('messages.completed'), 'status' => 'success','redirect' => '/login']);
}
如何在 login
上重定向此页面而不是在安装时再次重定向?
如果您将 /login
的路由命名为登录名,试试这个:
return redirect('login')->with('message', trans('messages.installation').' '.trans('messages.completed'))->with('status', 'success');
据我所知,json
函数不接受重定向参数。
之后,您可以从 session
:
访问 message
@if (session('message'))
{{ session('message') }}
@endif
我正在使用 xampp 服务器为我的项目使用来自 envato market 的 larapay 模板。我将分享我现在正在处理的代码。实际上我卡在了安装部分。我能够完成我的安装部分,它创建了 db 和所有,它向我显示了成功的消息,但它没有在登录页面上重定向。它重定向到同一安装页面。
但实际上又去安装了
我的web.php:
Route::resource('/install', 'AccController',['only' => ['index', 'store']]);
AccController.php :
public function store(AccRequest $request){
$link = @mysqli_connect($request->input('hostname'), $request->input('mysql_username'), $request->input('mysql_password'));
if (!$link)
return response()->json(['message' => trans('messages.connection_not_established'), 'status' => 'error']);
mysqli_select_db($link,$request->input('mysql_database'));
$count_table_query = mysqli_query($link,"show tables");
$count_table = mysqli_num_rows($count_table_query);
if (!is_file('../database/database.sql'))
return response()->json(['message' => trans('messages.database_file_not_found'), 'status' => 'error']);
if($count_table)
return response()->json(['message' => trans('messages.table_already_exists'), 'status' => 'error']);
$templine = '';
$lines = file('../database/database.sql');
foreach ($lines as $line)
{
if (substr($line, 0, 2) == '--' || $line == '')
continue;
$templine .= $line;
if (substr(trim($line), -1, 1) == ';')
{
mysqli_query($link,$templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
$templine = '';
}
}
$username = $request->input('username');
$password = bcrypt($request->input('password'));
$email = $request->input('email');
$first_name = $request->input('first_name');
$last_name = $request->input('last_name');
$default_role = config('constant.default_role');
$default_customer_role = config('constant.default_customer_role');
$default_staff_role = config('constant.default_staff_role');
$default_department = config('constant.default_department');
$default_designation = config('constant.default_designation');
mysqli_query($link, "insert into roles(name,is_hidden,is_default) values('$default_role','1','0'),('$default_customer_role','0','1'),('$default_staff_role','0','0')");
mysqli_query($link, "insert into departments(name,is_hidden) values('$default_department','1')");
mysqli_query($link, "insert into designations(department_id,name,is_hidden) values('1','$default_designation',1)");
mysqli_query($link, "insert into users(email,username,password,is_hidden,status) values('$email','$username','$password','1','active') ");
mysqli_query($link, "insert into profiles(user_id,first_name,last_name,designation_id) values('1','$first_name','$last_name','1') ");
mysqli_query($link, "insert into role_user(user_id,role_id) values('1','1') ");
envu([
'DB_HOST' => $request->input('hostname'),
'DB_NAME' => $request->input('mysql_database'),
'DB_USERNAME' => $request->input('mysql_username'),
'DB_PASSWORD' => $request->input('mysql_password')
]);
//complete($purchase_code);
$this->logActivity(['module' => 'application','activity' => 'installed']);
return response()->json(['message' => trans('messages.installation').' '.trans('messages.completed'), 'status' => 'success','redirect' => '/login']);
}
如何在 login
上重定向此页面而不是在安装时再次重定向?
如果您将 /login
的路由命名为登录名,试试这个:
return redirect('login')->with('message', trans('messages.installation').' '.trans('messages.completed'))->with('status', 'success');
据我所知,json
函数不接受重定向参数。
之后,您可以从 session
:
message
@if (session('message'))
{{ session('message') }}
@endif