草庐IT

php - 检查字符串是否包含任何文本

我有这个字符串:$mystring="SIZE,DETAIL";我正在使用:@if(strpos($mystring,'SIZE')){{$item->size}}@endif@if(strpos($mystring,'DETAIL')){{$item->detail}}@endif但这适用于SIZE,但不适用于DETAIL。这里有什么问题? 最佳答案 因为你使用的是Laravel,你可以使用str_contains()助手:@if(str_contains($mystring,'SIZE'))Thestr_containsfunc

php - 为什么 created_at updated_at 在插入时为空

在我的laravel项目中,我需要一次添加多条记录,我还想自动插入created_at和updated_at,因为它在save()中工作。但在插入方法中不起作用。for($i=0;$ilocation_id);$i++){$asset_arr[$i]['property_id']=$this->id;$asset_arr[$i]['location_id']=$req->location_id[$i];$asset_arr[$i]['model_id']=$req->model_id[$i];$asset_arr[$i]['appliance_owner']=$req->applian

php - Laravel 列表 concat 不显示数据(全名)

我在我的项目中使用Laravel5.3,我试图获取多个列并在View的下拉选择元素中显示数据。我正在做这样的查询:$users=User::select(DB::raw("CONCAT(first_name,'',last_name)ASfull_name,id"))->lists('full_name','id')->toArray();但这是我从中得到的数据:array:6[▼14=>""15=>""16=>""17=>""19=>""22=>""]full_name的值为空,我该如何解决? 最佳答案 尽量避免使用full_na

php - Laravel 5.3 存储和读取文件目录

目前正在尝试处理文件,但很难弄清楚将它们放在哪里以及如何在列表中读回它们。我尝试将几个测试文件放入$files=array();$dir=opendir(asset('files');//openthecwd..alsodoanerrcheck.while(false!=($file=readdir($dir))){if(($file!=".")and($file!="..")and($file!="index.php")){$files[]=$file;//putinarray.}}但尽管其中有3个测试文件,它还是返回空白。查看幼虫食谱和建议说File:allFile()这不是受支持

php - Laravel 路线不适用于生产

我有一个Laravel5/angularJS应用程序(将Laravel作为apirest和angular作为前端)在我的本地环境中,一切都像魅力一样运作。但是当我上传到主机时,我只能访问索引页面,其他所有内容都会抛出404。在我的共享主机中,我有这样的文件系统。public_htmllaravel-backend(ithasapp,bootstrap,confi...etc,alllaravelapp)laravel-frontend(itwouldbelikethepublicfolderofthelaraveldefaultfilesystem).htaccess.htaccess

php - Laravel 在一个函数中加载多个 View

我只知道如何在单个Controller函数中调用多个View。我正在尝试:returnView::make('header');returnView::make('main');returnView::make('footer');任何建议。我如何称呼他们?提前致谢.. 最佳答案 您应该使用sections创建一个View为了便于重复使用。然后它允许您组成各个部分。layout.blade.php@yield('header')@yield('body')@yield('footer')combined.blade.php@exte

php - 为什么在 laravel blade 中条件 @if 不工作? (拉拉维尔 5.3)

如果我的代码是这样的:@foreach($categoriesas$category)@if($loop->first)$category_id=$category->id@endif@endforeach存在错误:Undefinedvariable:category_id(View:C:\xampp\htdocs\myshop\resources\views\front.blade.php)如果我的代码是这样的:@foreach($categoriesas$category)@phpif($loop->first)$category_id=$category->id@endphp@e

php - 在 Laravel 5.4 中从迁移中删除列

我使用像这样的迁移创建了一个表:Schema::create('listings',function(Blueprint$table){$table->increments('id');$table->decimal('original_price',10,2);$table->decimal('discouted_price',10,2);$table->integer('city_id')->index()->unsigned()->nullable();$table->foreign('city_id')->references('id')->on('cities');$tabl

php - 如何验证以检查表中是否存在具有此值的记录?

我正在做一个Laravel项目,我有以下与验证相关的问题。过去我创建了这个验证规则(与新用户注册表相关):$rules=['name'=>'required','surname'=>'required','login'=>'required|unique:pm_user,login','email'=>'required|email|confirmed|unique:pm_user,email','pass'=>'required|required|min:6','g-recaptcha-response'=>'required|captcha',];特别是这个规则数组包含这个规则:'

php - 路由如何在 PHP laravel 中工作?

我刚开始玩Laravel框架,我看到了这个:Route::get('foo',function(){return'HelloWorld';});谁能解释一下这是什么?我的意思是,我知道什么是get。但是为什么我们先放'foo'然后放闭包呢?另外,我真正从哪里获得信息? 最佳答案 首先我们声明Route的Facade,想像一个使用Route类的捷径。然后我们选择路由的方法,可以是:Route::get($uri,$callback);//getRoute::post($uri,$callback);//postRoute::put($