Make suppliers deletable.
This commit is contained in:
@@ -18,6 +18,14 @@ class SupplierController extends Controller
|
||||
return response()->json($suppliers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function withTrashed(): JsonResponse
|
||||
{
|
||||
return response()->json(Supplier::with(['invoices'])->withTrashed()->orderBy('name')->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
@@ -69,4 +77,25 @@ class SupplierController extends Controller
|
||||
return response()->json($supplier);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Supplier $supplier): JsonResponse
|
||||
{
|
||||
$supplier->delete();
|
||||
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource.
|
||||
*/
|
||||
public function restore(int $id): JsonResponse
|
||||
{
|
||||
$supplier = Supplier::withTrashed()->findOrFail($id)->restore();
|
||||
|
||||
return response()->json($supplier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class Incoming extends Model
|
||||
*/
|
||||
public function supplier(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Supplier::class);
|
||||
return $this->belongsTo(Supplier::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,9 +4,12 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Supplier extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user