Tearing my hair out over this one... Cannot get soft deleting to work in Laravel 5.x.
The "deleted_at" column is never populated with the timestamp.
If I remove "use SoftDeletes" from the model, it deletes the item (as expected), but soft deleting does nothing.
Here is my code:
Model:
class UkRfpEntry extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'] ;
public function metadata()
{
return $this->hasOne('App\UkRfpEntryMetadata');
}
}
Contoller:
public function destroy(UkRfpEntry $uk_rfp_entry)
{
$uk_rfp_entry->delete();
}
(successful) Migration:
public function up()
{
Schema::table('uk_rfp_entries', function (Blueprint $table) {
$table->softDeletes();
});
}
AJAX request for deletion:
$.ajax({
url: "" + "/" + $(this).attr('id'), // the url where we want to POST
type: 'DELETE',
data: {
'_token': '',
'_method': 'DELETE',
},
dataType: 'json',
success: alert('success')
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire