Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| BrandController | n/a |
0 / 0 |
n/a |
0 / 0 |
8 | n/a |
0 / 0 |
|||
| index | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| create | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| store | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| edit | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| update | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Http\Requests\Brands\StoreBrandRequest; |
| 7 | use App\Http\Requests\Brands\UpdateBrandRequest; |
| 8 | use App\Models\Brand; |
| 9 | use Illuminate\Http\Request; |
| 10 | use Illuminate\Support\Facades\DB; |
| 11 | use Illuminate\Support\Str; |
| 12 | |
| 13 | /** |
| 14 | * @codeCoverageIgnore |
| 15 | */ |
| 16 | class BrandController extends Controller |
| 17 | { |
| 18 | /** |
| 19 | * Display a listing of the resource. |
| 20 | * |
| 21 | * @param \Illuminate\Http\Request $request |
| 22 | * @return \Illuminate\Http\Response |
| 23 | */ |
| 24 | public function index(Request $request) |
| 25 | { |
| 26 | /** @var \Illuminate\Database\Eloquent\Builder $query */ |
| 27 | $query = Brand::query(); |
| 28 | |
| 29 | if ($request->search) { |
| 30 | $this->searchQuery( |
| 31 | $query, |
| 32 | $request->search, |
| 33 | null, |
| 34 | 'name', |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | $this->sortQuery($query); |
| 39 | $searchFields = trans('Nom'); |
| 40 | |
| 41 | $brandModels = $query->paginate(12); |
| 42 | |
| 43 | return view('brands.index', compact('brandModels', 'searchFields')); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Show the form for creating a new resource. |
| 48 | * |
| 49 | * @param \App\Models\Brand $brands |
| 50 | * @return \Illuminate\Http\Response |
| 51 | */ |
| 52 | public function create(Brand $brands) |
| 53 | { |
| 54 | return view('brands.create', [ |
| 55 | 'brandModel' => $brands |
| 56 | ]); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Store a newly created resource in storage. |
| 61 | * |
| 62 | * @param \App\Http\Requests\Brands\StoreBrandRequest $request |
| 63 | * @return \Illuminate\Http\Response |
| 64 | */ |
| 65 | public function store(StoreBrandRequest $request) |
| 66 | { |
| 67 | return DB::transaction(function () use ($request) { |
| 68 | $brand = new Brand(); |
| 69 | $brand->fill($request->validated()); |
| 70 | if ($brand->saveOrFail()) { |
| 71 | return redirect() |
| 72 | ->route('brands.edit', $brand) |
| 73 | ->with('success', trans( |
| 74 | ':model a été créé.', |
| 75 | ['model' => Str::singular(trans('models.classes.brands'))] |
| 76 | )); |
| 77 | } |
| 78 | return redirect() |
| 79 | ->back() |
| 80 | ->with('error', trans( |
| 81 | ':model n\'a pas été créé.', |
| 82 | ['model' => Str::singular(trans('models.classes.brands'))] |
| 83 | )); |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Show the form for editing the specified resource. |
| 89 | * |
| 90 | * @param \App\Models\Brand $brands |
| 91 | * @return \Illuminate\Http\Response |
| 92 | */ |
| 93 | public function edit(Brand $brands) |
| 94 | { |
| 95 | return view('brands.edit', [ |
| 96 | 'brandModel' => $brands |
| 97 | ]); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Update a spacific resource in storage. |
| 102 | * |
| 103 | * @param \App\Http\Requests\Brands\UpdateBrandRequest $request |
| 104 | * @param \App\Models\Brand $brand |
| 105 | * @return \Illuminate\Http\Response |
| 106 | */ |
| 107 | public function update(UpdateBrandRequest $request, Brand $brand) |
| 108 | { |
| 109 | return DB::transaction(function () use ($request, $brand) { |
| 110 | $brand->fill($request->validated()); |
| 111 | if ($brand->saveOrFail()) { |
| 112 | return redirect() |
| 113 | ->route('brands.edit', $brand) |
| 114 | ->with('success', trans( |
| 115 | ':model a été mis à jour.', |
| 116 | ['model' => Str::singular(trans('models.classes.brands'))] |
| 117 | )); |
| 118 | } |
| 119 | return redirect() |
| 120 | ->back() |
| 121 | ->with('error', trans( |
| 122 | ':model n\'a pas été mis à jour.', |
| 123 | ['model' => Str::singular(trans('models.classes.brands'))] |
| 124 | )); |
| 125 | }); |
| 126 | } |
| 127 | } |