我在一对多关系中工作,其中用户模型在资产模型中有很多。我正在尝试创建一种方法,如果数据库名称列中的用户的资产名称已经存在,则无法再次上传。
$assets = Auth::user()->assets;
这^返回资产db中的两个资产行。
[{"id":18,"user_id":2,"name":"bootstrap.css","size":"153790","extension":"css","url":"\/\/cdn.aircss.io\/testing1\/bootstrap.css","subdirectory":"","created_at":"2015-05-26 05:21:59","updated_at":"2015-05-26 05:21:59"},{"id":19,"user_id":2,"name":"jquery.dynatable.js","size":"60347","extension":"js","url":"\/\/cdn.aircss.io\/testing1\/jquery.dynatable.js","subdirectory":"","created_at":"2015-05-26 05:22:12","updated_at":"2015-05-26 05:22:12"}]1
我只想在名称列中显示值,以便我可以运行我的if语句
if($assets == $filename)
{
return redirect('upload')->with('errornotice', 'A file with that name already exist');
}
答案 0 :(得分:0)
我能够弄清楚这一点。我的资产变量需要
$assets = Auth::user()->assets->first()->name;
在我的情况下,他们只会有一个文件名。