Ignore:
Timestamp:
10/17/21 18:39:50 (3 years ago)
Author:
Berat Kjufliju <kufliju@…>
Branches:
develop, master
Children:
bd9e8e3
Parents:
120759b
Message:

added validation to blades

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Dashboard/DepartmentsController.php

    r120759b rd795fa6  
    77use App\Http\Requests\Dashboard\UpdateDepartmentRequest;
    88use App\Models\Department;
     9use App\Models\Document;
    910use App\Models\User;
     11use Carbon\Carbon;
    1012use Illuminate\Http\Request;
    1113use App\Http\Controllers\Controller;
     
    2527    {
    2628        return view("dashboard.departments.create");
    27     }
    28 
    29     public function editShow($id)
    30     {
    31         return view("dashboard.departments.edit")->with([
    32             "department" => Department::findOrFail($id)
    33         ]);
    3429    }
    3530
     
    5550    }
    5651
     52    public function editShow($id)
     53    {
     54        return view("dashboard.departments.edit")->with([
     55            "department" => Department::findOrFail($id)
     56        ]);
     57    }
     58
    5759    public function edit(UpdateDepartmentRequest $request, $id)
    5860    {
     
    6365        $department->name = $request->name;
    6466        $department->code = $request->code;
     67        $department->updated_at = Carbon::now();;
    6568
    6669        $path = '/Departments/' . $request->code;
     
    8386    }
    8487
    85     public function destroy(Request $request, $id)
     88    public function destroy($id)
    8689    {
    8790        $department = Department::find($id);
     91        //$department->delete();
     92        $documents = $department->document()->count();
    8893
    89         $department->delete();
     94        if($documents > 0){
     95            Alert::flash($department->name . " has " . $documents . " document/s associated", "error");
     96        }
     97        else {
     98            $department->delete();
    9099
    91         Alert::flash($department->name . " deleted successfully");
     100            Alert::flash($department->name . " deleted successfully");
     101        }
    92102
    93103        return redirect()->route("dashboard.departments.index");
Note: See TracChangeset for help on using the changeset viewer.