Laravel: Soft Delete an item
up vote
-1
down vote
favorite
I would like to delete an item only on my page "overview" however I will wish to keep the element on my database. Is it possible ?
Do you have an idea of the procedure ?
I don't know how to do softdelete, in my Controller I have that
public function destroy(Devis $devis)
{
$devis->delete();
return redirect('/admin');
}
In my route I have that
Route::group(['middleware' => ['auth']], function () {
Route::get('/admin', 'AdminController@getHome');
Route::get('/valider/{devis}', 'AdminController@destroy');
});
In my file overview I have that
@foreach($devis as $item)
<tr>
<td> {{$item->firstname}}</td>
<td> {{$item->lastname}} </td>
<td> {{$item->phone}} </td>
<td> {{$item->start_adress}} -- {{$item->start_floor}}</td>
<td> {{$item->end_adress}} -- {{$item->end_floor}}</td>
<td> {{$item->type_intervention}}</td>
<td> {{$item->email}} </td>
<td> {{$item->remarks}} </td>
<td> <a href="/valider/{{$item->id}}" class="btn btn-danger"><span class="left ion-close"></span></a></td>
</tr>
@endforeach
php laravel soft-delete
add a comment |
up vote
-1
down vote
favorite
I would like to delete an item only on my page "overview" however I will wish to keep the element on my database. Is it possible ?
Do you have an idea of the procedure ?
I don't know how to do softdelete, in my Controller I have that
public function destroy(Devis $devis)
{
$devis->delete();
return redirect('/admin');
}
In my route I have that
Route::group(['middleware' => ['auth']], function () {
Route::get('/admin', 'AdminController@getHome');
Route::get('/valider/{devis}', 'AdminController@destroy');
});
In my file overview I have that
@foreach($devis as $item)
<tr>
<td> {{$item->firstname}}</td>
<td> {{$item->lastname}} </td>
<td> {{$item->phone}} </td>
<td> {{$item->start_adress}} -- {{$item->start_floor}}</td>
<td> {{$item->end_adress}} -- {{$item->end_floor}}</td>
<td> {{$item->type_intervention}}</td>
<td> {{$item->email}} </td>
<td> {{$item->remarks}} </td>
<td> <a href="/valider/{{$item->id}}" class="btn btn-danger"><span class="left ion-close"></span></a></td>
</tr>
@endforeach
php laravel soft-delete
here is some great explaintion: stackoverflow.com/questions/22426165/laravel-soft-delete-posts
– Naveed Ali
Nov 7 at 10:56
Try to use google before asking on SO unless you don't understand how it works and need a different explanation. Don't just ask your questions without searching on google.
– killstreet
Nov 8 at 12:00
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I would like to delete an item only on my page "overview" however I will wish to keep the element on my database. Is it possible ?
Do you have an idea of the procedure ?
I don't know how to do softdelete, in my Controller I have that
public function destroy(Devis $devis)
{
$devis->delete();
return redirect('/admin');
}
In my route I have that
Route::group(['middleware' => ['auth']], function () {
Route::get('/admin', 'AdminController@getHome');
Route::get('/valider/{devis}', 'AdminController@destroy');
});
In my file overview I have that
@foreach($devis as $item)
<tr>
<td> {{$item->firstname}}</td>
<td> {{$item->lastname}} </td>
<td> {{$item->phone}} </td>
<td> {{$item->start_adress}} -- {{$item->start_floor}}</td>
<td> {{$item->end_adress}} -- {{$item->end_floor}}</td>
<td> {{$item->type_intervention}}</td>
<td> {{$item->email}} </td>
<td> {{$item->remarks}} </td>
<td> <a href="/valider/{{$item->id}}" class="btn btn-danger"><span class="left ion-close"></span></a></td>
</tr>
@endforeach
php laravel soft-delete
I would like to delete an item only on my page "overview" however I will wish to keep the element on my database. Is it possible ?
Do you have an idea of the procedure ?
I don't know how to do softdelete, in my Controller I have that
public function destroy(Devis $devis)
{
$devis->delete();
return redirect('/admin');
}
In my route I have that
Route::group(['middleware' => ['auth']], function () {
Route::get('/admin', 'AdminController@getHome');
Route::get('/valider/{devis}', 'AdminController@destroy');
});
In my file overview I have that
@foreach($devis as $item)
<tr>
<td> {{$item->firstname}}</td>
<td> {{$item->lastname}} </td>
<td> {{$item->phone}} </td>
<td> {{$item->start_adress}} -- {{$item->start_floor}}</td>
<td> {{$item->end_adress}} -- {{$item->end_floor}}</td>
<td> {{$item->type_intervention}}</td>
<td> {{$item->email}} </td>
<td> {{$item->remarks}} </td>
<td> <a href="/valider/{{$item->id}}" class="btn btn-danger"><span class="left ion-close"></span></a></td>
</tr>
@endforeach
php laravel soft-delete
php laravel soft-delete
edited Nov 7 at 11:40
Salman Zafar
814619
814619
asked Nov 7 at 10:33
anais_stem
117
117
here is some great explaintion: stackoverflow.com/questions/22426165/laravel-soft-delete-posts
– Naveed Ali
Nov 7 at 10:56
Try to use google before asking on SO unless you don't understand how it works and need a different explanation. Don't just ask your questions without searching on google.
– killstreet
Nov 8 at 12:00
add a comment |
here is some great explaintion: stackoverflow.com/questions/22426165/laravel-soft-delete-posts
– Naveed Ali
Nov 7 at 10:56
Try to use google before asking on SO unless you don't understand how it works and need a different explanation. Don't just ask your questions without searching on google.
– killstreet
Nov 8 at 12:00
here is some great explaintion: stackoverflow.com/questions/22426165/laravel-soft-delete-posts
– Naveed Ali
Nov 7 at 10:56
here is some great explaintion: stackoverflow.com/questions/22426165/laravel-soft-delete-posts
– Naveed Ali
Nov 7 at 10:56
Try to use google before asking on SO unless you don't understand how it works and need a different explanation. Don't just ask your questions without searching on google.
– killstreet
Nov 8 at 12:00
Try to use google before asking on SO unless you don't understand how it works and need a different explanation. Don't just ask your questions without searching on google.
– killstreet
Nov 8 at 12:00
add a comment |
5 Answers
5
active
oldest
votes
up vote
0
down vote
accepted
Laravel already did it look here so you add deleted_at in your model and
as docs said your model is like:
namespace App;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Flight extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
add a comment |
up vote
0
down vote
When you want to soft delete actually you need a flag. Let's say that in your table you have a column deleted which accepts boolean values.
When you retrieve the data in your controller to pass it to the view then you will query the table you just put a where
clause to your query something like:
->where('deleted',0)
So you get the "undeleted" items.
Now when you want to softdelete actually you don't delete but you update your column to set it's status to 1.
add a comment |
up vote
0
down vote
Use this: Documentation soft deleting
later add to the conditions for downloading items
->whereNull('deleted_at')
add a comment |
up vote
0
down vote
Laravel has it's own implementation of soft deleting. Simply add use SoftDeletes
to your model, and it starts working. Try reading Eloquent - Soft deletes to learn more about it and its implications on your code.
add a comment |
up vote
0
down vote
You must add a field to soft delete
when creating the table. It's best to migrate. If it will be and you'll use soft delete
then:
$ item-> delete () - will be softdelete
$ item-> forcedelete () - will permanently delete
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Laravel already did it look here so you add deleted_at in your model and
as docs said your model is like:
namespace App;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Flight extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
add a comment |
up vote
0
down vote
accepted
Laravel already did it look here so you add deleted_at in your model and
as docs said your model is like:
namespace App;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Flight extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Laravel already did it look here so you add deleted_at in your model and
as docs said your model is like:
namespace App;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Flight extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
Laravel already did it look here so you add deleted_at in your model and
as docs said your model is like:
namespace App;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Flight extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
namespace App;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Flight extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
namespace App;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Flight extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
answered Nov 7 at 10:39
sharif854
964
964
add a comment |
add a comment |
up vote
0
down vote
When you want to soft delete actually you need a flag. Let's say that in your table you have a column deleted which accepts boolean values.
When you retrieve the data in your controller to pass it to the view then you will query the table you just put a where
clause to your query something like:
->where('deleted',0)
So you get the "undeleted" items.
Now when you want to softdelete actually you don't delete but you update your column to set it's status to 1.
add a comment |
up vote
0
down vote
When you want to soft delete actually you need a flag. Let's say that in your table you have a column deleted which accepts boolean values.
When you retrieve the data in your controller to pass it to the view then you will query the table you just put a where
clause to your query something like:
->where('deleted',0)
So you get the "undeleted" items.
Now when you want to softdelete actually you don't delete but you update your column to set it's status to 1.
add a comment |
up vote
0
down vote
up vote
0
down vote
When you want to soft delete actually you need a flag. Let's say that in your table you have a column deleted which accepts boolean values.
When you retrieve the data in your controller to pass it to the view then you will query the table you just put a where
clause to your query something like:
->where('deleted',0)
So you get the "undeleted" items.
Now when you want to softdelete actually you don't delete but you update your column to set it's status to 1.
When you want to soft delete actually you need a flag. Let's say that in your table you have a column deleted which accepts boolean values.
When you retrieve the data in your controller to pass it to the view then you will query the table you just put a where
clause to your query something like:
->where('deleted',0)
So you get the "undeleted" items.
Now when you want to softdelete actually you don't delete but you update your column to set it's status to 1.
answered Nov 7 at 10:37
pr1nc3
3,0732520
3,0732520
add a comment |
add a comment |
up vote
0
down vote
Use this: Documentation soft deleting
later add to the conditions for downloading items
->whereNull('deleted_at')
add a comment |
up vote
0
down vote
Use this: Documentation soft deleting
later add to the conditions for downloading items
->whereNull('deleted_at')
add a comment |
up vote
0
down vote
up vote
0
down vote
Use this: Documentation soft deleting
later add to the conditions for downloading items
->whereNull('deleted_at')
Use this: Documentation soft deleting
later add to the conditions for downloading items
->whereNull('deleted_at')
answered Nov 7 at 10:37
Mateusz Czerwiński
336
336
add a comment |
add a comment |
up vote
0
down vote
Laravel has it's own implementation of soft deleting. Simply add use SoftDeletes
to your model, and it starts working. Try reading Eloquent - Soft deletes to learn more about it and its implications on your code.
add a comment |
up vote
0
down vote
Laravel has it's own implementation of soft deleting. Simply add use SoftDeletes
to your model, and it starts working. Try reading Eloquent - Soft deletes to learn more about it and its implications on your code.
add a comment |
up vote
0
down vote
up vote
0
down vote
Laravel has it's own implementation of soft deleting. Simply add use SoftDeletes
to your model, and it starts working. Try reading Eloquent - Soft deletes to learn more about it and its implications on your code.
Laravel has it's own implementation of soft deleting. Simply add use SoftDeletes
to your model, and it starts working. Try reading Eloquent - Soft deletes to learn more about it and its implications on your code.
answered Nov 7 at 10:38
Maaike Brouwer
942
942
add a comment |
add a comment |
up vote
0
down vote
You must add a field to soft delete
when creating the table. It's best to migrate. If it will be and you'll use soft delete
then:
$ item-> delete () - will be softdelete
$ item-> forcedelete () - will permanently delete
add a comment |
up vote
0
down vote
You must add a field to soft delete
when creating the table. It's best to migrate. If it will be and you'll use soft delete
then:
$ item-> delete () - will be softdelete
$ item-> forcedelete () - will permanently delete
add a comment |
up vote
0
down vote
up vote
0
down vote
You must add a field to soft delete
when creating the table. It's best to migrate. If it will be and you'll use soft delete
then:
$ item-> delete () - will be softdelete
$ item-> forcedelete () - will permanently delete
You must add a field to soft delete
when creating the table. It's best to migrate. If it will be and you'll use soft delete
then:
$ item-> delete () - will be softdelete
$ item-> forcedelete () - will permanently delete
edited Nov 7 at 11:14
Salman Zafar
814619
814619
answered Nov 7 at 10:37
Łukasz Matejka
113
113
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187693%2flaravel-soft-delete-an-item%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
here is some great explaintion: stackoverflow.com/questions/22426165/laravel-soft-delete-posts
– Naveed Ali
Nov 7 at 10:56
Try to use google before asking on SO unless you don't understand how it works and need a different explanation. Don't just ask your questions without searching on google.
– killstreet
Nov 8 at 12:00