我有一个问题,我不能在laravel 5.2中使用策略.
我有2张桌子,学生和任务.
我尝试应用策略来阻止通过更改URL来编辑任务,但我总是收到消息此操作未经授权,尽管任务是正确的用户.
政策代码:
<?php
namespace App\Policies;
use App\Models\Student;
use App\Models\Task;
class TasksPolicy
{
public function edit(Student $student, Task $tasks)
{
return $student->id === $tasks->student_id;
}
}
Run Code Online (Sandbox Code Playgroud)
AuthServiceProvider.php中的代码
<?php
namespace App\Providers;
use App\Models\Task;
use App\Policies\TasksPolicy;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
Task::class => TasksPolicy::class
];
Run Code Online (Sandbox Code Playgroud)
然后在TaskController.php文件中调用:
public function edit($id)
{
$tasks = Task::findOrFail($id);
$this->authorize('edit', $tasks);
return view('tasks.edit', …Run Code Online (Sandbox Code Playgroud) 我有一个集合,其中我以降序排列“总”值。当“总计”值相同时,我必须按降序日期对项目进行排序。
$collection->sortByDesc('total');
Run Code Online (Sandbox Code Playgroud)
为了在总数相等时按降序日期对元素进行排序,我使用了sortandsortByDesc但元素仍然没有排序。
//First method
$collection->sortByDesc('created_at')->sortByDesc('total');
//Second method
$collection->->sort(function($a, $b){
if($a->total === $b->total)
{
return strtotime($a->created_at) - strtotime($b->created_at);
}
})->sortByDesc('total');
Run Code Online (Sandbox Code Playgroud)
这两个选项都不适合我,我仍然得到相同的结果:
当结果应如下时(当总值相等时,按下降日期排序项目):
我究竟做错了什么?
PS:它不能帮助我按“总计”排序,然后按“日期”排序,因为“总计”值应该是优先考虑的值。
如何仅在输入大于 3(或 N)个字符时应用过滤器来获得 ng-repeat 的结果?
我尝试了以下(过滤器: input.lenght > 3):
<input type="text" ng-model="input" placeholder="Search">
<li ng-repeat="detail in details | filter: input.lenght > 3">
{{ detail.name }}
</li>
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我怎样才能做我想做的事?问候朋友。
解决方案:
<input type="text" ng-model="input" ng-minlength="3" placeholder="Search">
Run Code Online (Sandbox Code Playgroud)