I have an Eloquent Model called Coin, with fillable attributes set. I have a Form on the page, which when I check $request->all()
I can confirm is submitting correctly.
I have a FormRequest object with rules returning an empty array. (I'll add them later.)
The problem is, FormRequest $request->validate()
returns an empty array which is probably wrong. It should be returning an array of my request items. I cannot figure out why this is happening!
Here is my controller method:
public function update(UpdateCoin $request, Coin $coin)
{
$this->authorize('update', $coin);
$coin->update($request->validated());
$this->log('Coin %s (%s) was updated by user %s.', $coin->name, $coin->symbol, auth()->user()->id);
$request->session()->flash('success', 'alerts.coin_updated');
return redirect()->route('admin.coins.show', [$coin->id]);
}
This is the FormRequest class:
class UpdateCoin extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
This is the Coin Model:
/**
* Defines a coin model.
*/
class Coin extends Model
{
use Eloquence;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'symbol',
'pair',
'logo',
'description',
'primary_color',
'secondary_color',
'website',
'wallet_name',
'wallet_site',
'wallet_description',
'exchange',
'marketcap',
'active',
];
...
var_dump($request->all())
proves the form is submitting with the new values.
var_dump($request->validated()
returns an empty array, which shows that something is wrong, but I have absolutely no idea why.
I have another model which does the same thing, and I've spent a few hours now comparing them and they're for all intent and purpose, identical.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire