58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Nova\Actions;
|
|
|
|
use App\Models\Contest;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Support\Collection;
|
|
use Laravel\Nova\Actions\Action;
|
|
use Laravel\Nova\Fields\ActionFields;
|
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
|
use Lexicon\ActionButtonSelector\ActionAsButton;
|
|
use App\Http\Controllers\TwitterController;
|
|
|
|
class Participer extends Action
|
|
{
|
|
use InteractsWithQueue, Queueable;
|
|
use ActionAsButton;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->withoutConfirmation();
|
|
}
|
|
|
|
/**
|
|
* Perform the action on the given models.
|
|
*
|
|
* @param \Laravel\Nova\Fields\ActionFields $fields
|
|
* @param \Illuminate\Support\Collection $models
|
|
* @return mixed
|
|
*/
|
|
public function handle(ActionFields $fields, Collection $models)
|
|
{
|
|
if($models->first()->participated == 1){
|
|
Action::danger('Vous avez déjà participé');
|
|
}
|
|
else{
|
|
$contest = Contest::find($models->first()->id);
|
|
$contest->participated = 1;
|
|
$contest->save();
|
|
Action::message('Participation en cours');
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Get the fields available on the action.
|
|
*
|
|
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
|
* @return array
|
|
*/
|
|
public function fields(NovaRequest $request)
|
|
{
|
|
return [];
|
|
}
|
|
}
|