我正在使用larved页面在laravel中构建一个应用程序。在一个粗糙页面上,当2个数据库对象被链接时,我需要有一个视觉提示。我有用户和卡。原始页面显示了所有卡片,我需要具有现有卡片/用户关系的卡片以具有一些其他样式才能脱颖而出。
我已经阅读了有关编辑标准存储和更新功能的信息,但它并不是我想要的。截至目前,我的页面仅可通过crudcontroller,模型和路线使用。
功能测试是一种选择需要具有不同风格的卡的测试。这是crudcontroller:
public function setup()
{
// get the user_id parameter
$usid= \Route::current()->parameter('usid');
$this->crud->setModel('App\Models\Koppel');
$this->crud->setRoute(config('backpack.base.route_prefix').'/users/'.$usid.'/koppel');
$this->crud->setEntityNameStrings('koppel', 'koppels');
$this->crud->denyAccess('update');
$this->crud->denyAccess('delete');
$this->crud->removeButton('create');
$this->crud->addButtonFromView('line', 'confirm', 'confirm', 'end');
$this->crud->addButtonFromView('line', 'remove', 'remove', 'end');
$this->crud->addButtonFromView('line', 'test', 'test', 'end');
//Columns
$this->crud->addColumn(['name' => 'name', 'type' => 'text', 'label' => "Card"]);
// add asterisk for fields that are required in KoppelRequest
$this->crud->setRequiredFields(StoreRequest::class, 'create');
$this->crud->setRequiredFields(UpdateRequest::class, 'edit');
}
public function store(StoreRequest $request)
{
// your additional operations before save here
$redirect_location = parent::storeCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
public function update(UpdateRequest $request)
{
// your additional operations before save here
$redirect_location = parent::updateCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
public function confirm($usID, $kID)
{
//link card to user by making card_user object
$koppel = \App\CardUser::updateOrCreate(['card_id' => $kID, 'user_id' => $usID]);
return Redirect::back();
}
public function remove($usID, $kID)
{
//find card_user with user_id and card_id then remove link
$deletedRows = \App\CardUser::where(['card_id' => $kID, 'user_id' => $usID])->delete();
return Redirect::back();
}
public function test($usID, $kID)
{
$cardID= \App\CardUser::where('user_id', $usID)->pluck('card_id')->toArray();
foreach ($cardID as $object) {
$card = \App\Card::where('id', $cardID)->get();
//change style for every $card
}
return Redirect::back();
}
这是模型:
class Koppel extends Model
{
use CrudTrait;
protected $table = 'instructiekaarten';
public $timestamps = true;
protected $fillable = ['name'];
}
我需要知道是否有可能根据我的功能更改某些原始记录的样式(大概在页面加载之前)。我还需要知道在页面加载之前将函数放在哪里运行它。 “更改样式”将类似于使一些记录变为绿色,同时保持其余记录为灰色。