在LoginController中登录后,我们可以覆盖此属性以重定向用户:
protected $redirectTo = '/home';
Run Code Online (Sandbox Code Playgroud)
以下是文档中的声明:
如果重定向路径需要自定义生成逻辑,则可以定义redirectTo方法而不是redirectTo属性:
受保护的函数redirectTo(){
//}
但它总是重定向到'/home';
任何条件.
protected function redirectTo()
{
if (Auth::user()->role==0) {
return '/volunteer';
} else {
return '/donor';
}
}
Run Code Online (Sandbox Code Playgroud)
如果存在方法,它将使用它,否则将使用该属性.但即使方法存在,它看起来似乎正在使用属性.
但是覆盖authenticated()
或sendLoginResponse()
功能正常.
protected function authenticated()
{
if (Auth::user()->role==0) {
return redirect('/volunteer') ;
} else {
return redirect('/donor');
}
}
Run Code Online (Sandbox Code Playgroud)
redirectTo()
方法有什么问题?这是这些方法的GitHub源代码.
我正在使用Laravel版本5.3.28.
我正在使用bootstrap选择.
<select name="categories[]" id="cat" class="selectpicker" multiple>
</select>
Run Code Online (Sandbox Code Playgroud)
从这里获取选项标签,
var result='';
for(var i=0; i<res.getcategories.length; i++)
{
result += '<option value='+res.getcategories[i].cat_id+'>'+res.getcategories[i].category+'</option>';
$('#cat').html(result);
}
Run Code Online (Sandbox Code Playgroud)
但是它总是显示没有选择,我不显示其他选项.如果我不使用bootstap类'selectpicker'一切都很好.
有什么方法可以通过集合获取刀片 foreach 循环中的迭代数?我将把它用于选定的下拉输入默认值。(我不想使用“表单模型绑定”)
我尝试论文,但它们不起作用,可能导致论文在对象的 foreach 循环中获取索引值:
key($theArrayYouAreLoopingThrough)
{{ @index }}
@foreach ($athletes as $key=>$athlete)
{{ ++$key }}
@endforeach
Run Code Online (Sandbox Code Playgroud)
等等。
我正在尝试查询数据库并在闭包函数中创建一个过滤器,我的模型(简体)如下所示:
Products:
id,
sale_id
Sales:
id,
provider_id
Provider:
id
Run Code Online (Sandbox Code Playgroud)
我想要来自特定提供商的所有产品,所以我构建了我的查询:
Product::with(array
('sale'=>function($query){
$query->where('provider_id', '=', 1);
})
)->get();
Run Code Online (Sandbox Code Playgroud)
问题是结果包含销售的正确产品,以及销售空的错误产品,如下所示:
[{
"id": 25,
"sale": null
},
{
"id": 26,
"sale": {
"id": 15,
"provider_id": 3
}
}]
Run Code Online (Sandbox Code Playgroud)
销售的产品:null是来自其他提供商的产品,我可以在内存中过滤它们,但我认为有一种方法可以避免查询的空结果,任何线索?
我有一个问题,我一直在开发laravel应用程序,我遇到了这个奇怪的错误:
QueryException in Connection.php line 770:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`testenv`.`products`, CONSTRAINT `products_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`)) (SQL: insert into `products` () values ())
Run Code Online (Sandbox Code Playgroud)
这是我的商店功能
public function store(Request $request)
{
$product = new Product;
/*
$product->name = $request->name;
$product->stockQty = $request->stockQty;
$product->minimumQty = $request->minimumQty;
$product->description = $request->description;
$product->notes = $request->notes;
$product->tenantMargin = $request->tenantMargin;
$product->length = $request->length;
$product->height = $request->height;
$product->weight = $request->weight;
$product->showLength = $request->showLength; …
Run Code Online (Sandbox Code Playgroud) 我点击删除按钮时运行此代码:
$(document).on('click', '.remove', function (e) {
e.preventDefault();
var id = $(this).data('id');
$.ajax({
type: "POST",
url: "<?php echo Yii::$app->request->baseUrl;?>"+'/todo/deletetask',
data: {id:id},
success: function (data) {
var res = $.parseJSON(data);
if(res != false) {
swal({
title: "Are you sure!",
type: "error",
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes!",
showCancelButton: true,
},
function(){
window.location.href = "<?php echo Yii::$app->request->baseUrl;?>/todo/index/";
});
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
控制器动作是:
public function actionDeletetask()
{
if(Yii::$app->request->isAjax)
{
$id = $_POST['id'];
if($id)
{
Todo::find()->where(['todo_id'=>$id])->one()->delete();
}
echo json_encode(TRUE);die;
}
echo json_encode(FALSE);die;
}
Run Code Online (Sandbox Code Playgroud)
但即使我点击甜蜜警报取消按钮,任务也会被删除,这是显而易见的.但我该怎样才能阻止它呢?