草庐IT

php - 如何在 laravel 5.1 blade 中回显字符串和变量

我在我的PHP文件中使用这段代码:university.blade.php{{url($universities->universityName.'/students')}}">问题是只显示http://localhost:8000/students,而不是变量的值。那么解决方案是什么? 最佳答案 可能$universities->universityName是空的让我们假设您的Controller如下所示:然后在你的universities.blade.phpuniversityName}/students")!!}">Stude

php - 登录表单 POST 上的 Laravel 5.1 token 不匹配

我在compiled.php第2930行中收到以下错误TokenMismatchException:代码在RedHat服务器上运行php5.6我也在Ubuntu服务器上运行php5.5.9它工作得很好。它还在本地完美运行。它似乎在原始GET请求的storage/framework/sessions中创建了2个session文件,这意味着当通过POST发送表单时>session就不同了。我检查过重定向服务器上的日期/时区问题session.php和app.php中的配置问题最奇怪的是为什么在GET请求中生成了2个session文件。一旦您点击登录按钮,您就会点击csrf中间件,说toke

php - Laravel 5.1 Dynamic where/orWhere

我想构建一个像这样的动态where/orWhere语句。$matchList=['match1','match2','match3','match4'];$query->where('Column','Like','match1')->orWhere('Column','Like','match2')->orWhere('Column','Like','match3')->orWhere('Column','Like','match4');我试图构建一个动态方法调用,但它不起作用......$matchList=['match1','match2','match3','match4']

php - Laravel 5.1 - 将参数传递给面包屑

我使用davejamesmillerBreadcrumbs包。我想知道如何将参数传递给面包屑,比如id。在文档(here)中说这是可能的,但找不到实现它的方法。我的目标是做这样的面包屑:Dashboard\User\NewModel。NewModel是一种添加与用户有某种关系的模型数据的形式。如果没有user_id参数,User的链接将不起作用。有什么想法吗? 最佳答案 可以传递全局变量\View::share('variable2',$variable2);如果在布局中呈现面包屑或者你需要在`user.new_model.blad

php - laravel 5.1 本地化不工作

我对laravel5.1的本地化有一些疑问我已经在主lang文件夹中插入了各种langs文件。在那里,我有“en”文件夹和“ru”文件夹等。例如:主页.php:return['something'=>'somethingtesting',];在route我有这个GET:get('/gui/{lang}/{id}/{ver}/',['as'=>'gui','uses'=>'GuiController@home']);但是语言并没有改变。如果我更改路由URL,文本将始终使用“en”默认语言。一些例子:http://domain.com/gui/en/1/homehttp://domain.

php - Laravel 5.1 删除关系

我的模型关系是oneToMany例如:PatientToSample患者模型:classPatient_ModelextendsModelimplementsJsonable{useSoftDeletes;protected$table='patients';publicfunctionsamples(){return$this->hasMany('App\Models\Sample_Model','code','patient_id');}}示例模型:classSample_ModelextendsModel{useSoftDeletes;protected$table='sampl

php - 拉维 5.1 : How to share a collection in all views?

我需要在所有View中共享一个集合。此集合包含网站新闻:$news=NewsStory::orderBy('created_at','desc')->paginate(5);我该怎么做? 最佳答案 可以分享ViewData所有View之间。只需将这一行添加到App\Providers\AppServiceProvider中的boot()方法:view()->share('news',NewsStory::orderBy('created_at','desc')->paginate(5));

php - 即使在包含 laravel Collective 之后,Laravel 5.1 Blade 也无法正常工作

composer.json{"name":"laravel/laravel","description":"TheLaravelFramework.","keywords":["framework","laravel"],"license":"MIT","type":"project","require":{"php":">=5.5.9","laravel/framework":"5.1.*","laravelcollective/html":"5.1.*"},"require-dev":{"fzaninotto/faker":"~1.4","mockery/mockery":"0.9

php - 在 Laravel 5.1 中验证失败时填充动态 html 元素

在我的表单中,我使用ajax填充州和城市下拉列表。此外,在同一个表单上,用户可以通过单击“添加更多按钮”来添加多个员工。在上述两种情况下,HTMLDOM元素都是使用jquery生成的。我需要重新构建动态生成的元素,以防表单提交时验证失败。谁能告诉我实现上述问题的正确方法。谢谢。 最佳答案 假设您通过调用js函数动态生成了一个输入列表,可能类似于//JSfunctiongenerate(){$("#container-abc").append("");}提交它们,如果存在验证错误,您将使用以下方法取回值://inyourblade$n

php - 在没有完整路径的情况下使用自定义助手 - Laravel 5.1

我有一个截断字符串的方法。StringHelper::truncate()当我在我的View中使用此方法时,它找不到类StringHelper。我已将它添加到composer.json并完成了转储自动加载。当我指定完整路径时,它会起作用:\App\Http\Helpers\StringHelper但我想有第一个选项。我该怎么做?AppServiceProvider也许可以,但是怎么做呢? 最佳答案 Laravel5.1的正确方法创建Bladedirective在AppServiceProvider类中:classAppService