I am trying to create a 'favouriting' system where i need to check if the 'dish' is already favourited or not. I am having some troubles figuring out how to do so.
I am on my 'Resturant' show page, which contains the following:
Resturant Controller:
public function show($id)
{
$resturant = Resturant::find($id);
$favourites = Favourite::all();
return view('resturants.resturant_show')->with('resturant', $resturant)->with('dishes', Dish::all())
->with('favourites', Favourite::all());
}
Resturant_show:
<div class="row row-cols-1 row-cols-md-3 g-4 m-3">
#foreach ($dishes as $dish)
#if ($resturant->id == $dish->resturant_id)
<div class="col">
<div class="card h-100">
//accessing $dish->id etc here, taken out to reduce snippet size
#foreach ($favourites as $favourite)
#if ($dish->id == $favourite->user_id)
<form method="POST" action='{{ url("favourite/$favourite->id") }}'>
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button
class="btn btn-outline-danger
type="submit" value="Delete"></3</button>
</form>
#else
<form method="POST" action='{{ url("favourite/$favourite->id") }}'>
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button
class="btn btn-outline-danger"
type="submit" value="Delete"><3</button>
</form>
#endif
#endforeach
<button type="button"
class="btn btn-outline-primary">
${{ $dish->price }} <span
class="rounded-pill bg-danger">Discount
#%</span>
</button>
</div>
</div>
</div>
#endif
#endforeach
</div>
#foreach ($favourites as $favourite)
#if ($dish->id == $favourite->user_id)
This is where I am looking to only display a single button (currently one foreach as I don't know how to find the right favourite data).
My relationships look like such:
Favourite
//Relationship with user
function user() {
return $this->belongsTo('App\Models\User', 'user_id');
}
//Relationship with dish
function dish() {
return $this->belongsTo('App\Models\Dish', 'dish_id');
}
Dish
//Relationship with resturant
function resturant() {
return $this->belongsTo('App\Models\Resturant', 'resturant_id');
}
//Relationship with favourite
function favourite() {
return $this->hasMany('App\Models\Favourite', 'favourite_id');
}
Resturant
//Relationship with user
function user() {
return $this->belongsTo('App\Models\User', 'user_id');
}
//Relationship with dish
function dish() {
return $this->hasMany('App\Models\Dish', 'dish_id');
}
Related
I have a create form for creating courses, I have assigned users to these courses however for some reason it is not working anymore. I have been through my code umpteen times and I can't find anything that has changed - so i have come here for help.
To give some context below is my index.blade.php. As you can see I have previously assigned users to a course.
Create.blade.php;
#extends('layouts.app')
#section('content')
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Create Course</div>
<div class="card-body">
<form method="POST" action="{{ route('admin.courses.store') }}" enctype="multipart/form-data">
#csrf
<div class="form-group">
<label class="required" for="name">Course Title</label>
<input class="form-control" type="text" name="title" id="id" value="{{ old('title', '') }}" required>
#if($errors->has('name'))
<div class="invalid-feedback">
{{ $errors->first('name') }}
</div>
#endif
</div>
<div class="form-group">
#can('create_courses')
{!! Form::label('Instructor', 'Instructor', ['class' => 'control-label']) !!}
{!! Form::select('Instructor[]', $instructors, Request::get('Instructor'), ['class' => 'form-control select2', 'multiple' => 'multiple']) !!}
#if($errors->has('Instructor'))
{{ $errors->first('Instructor') }}
#endif
#endcan
</div>
<div class="form-group">
<button class="btn btn-danger" type="submit">
Save
</button>
</div>
</div>
</form>
</div>
</div>
#endsection
Index.blade.php;
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<p>
#can('create_courses')
<button type="button" class="btn btn-success">Create Course</button>
#endcan('create_courses')
</p>
<div class="card">
<div class="card-header">Courses</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Course Title</th>
<th>Instructor</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
#foreach($course as $course)
<tr>
<th scope="row">{{ $course->id }}</th>
<td>{{ $course->title}}</td>
<td>{{ implode (', ', $course->instructors()->pluck('name')->toArray()) }}</td>
<td>
#can('edit_courses')
<a class="btn btn-xs btn-secondary" href="{{ route('admin.modules.index', $course->id) }}">
Modules
</a>
#endcan
</td>
<td>
#can('edit_courses')
<a class="btn btn-xs btn-primary" href="{{ route('admin.courses.edit', $course->id) }}">
Edit
</a>
#endcan
</td>
<td>
#can('delete_courses')
<form action="{{ route('admin.courses.destroy', $course->id) }}" method="POST" onsubmit="return confirm('Confirm delete?');" style="display: inline-block;">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="btn btn-xs btn-danger" value="Delete">
</form>
#endcan
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- <div class="col-md-2 col-lg-2">
<div class="list-unstyled">
Courses
Modules
</div>
</div> -->
</div>
</div>
#endsection
CoursesController.php;
<?php
namespace App\Http\Controllers\Admin;
use Gate;
use App\User;
use App\Course;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
class CoursesController extends Controller
{
public function __construct()
{
//calling auth middleware to check whether user is logged in, if no logged in user they will be redirected to login page
$this->middleware('auth');
}
public function index()
{
if(Gate::denies('manage_courses')){
return redirect(route('home'));
}
$courses = Course::all();
return view('admin.course.index')->with('course', $courses); //pass data down to view
}
public function create()
{
if(Gate::denies('create_courses')){
return redirect(route('home'));
}
$instructors = User::whereHas('role', function ($query) {
$query->where('role_id', 2); })->get()->pluck('name'); //defining instructor variable to call in create.blade.php. Followed by specifying that only users with role_id:2 can be viewed in the select form by looping through the pivot table to check each role_id
return view('admin.course.create', compact('instructors')); //passing instructor to view
}
public function store(Request $request)
{
$course = Course::create($request->all()); //request all the data fields to store in DB
$course->instructors()->sync($request->input('instructors', [])); //input method retrieves all of the input values as an array
if($course->save()){
$request->session()->flash('success', 'The course ' . $course->title . ' has been created successfully.');
}else{
$request->session()->flash('error', 'There was an error creating the course');
}
return redirect()->route ('admin.courses.index');
}
public function destroy(Course $course)
{
if(Gate::denies('delete_courses'))
{
return redirect (route('admin.course.index'));
}
$course->delete();
return redirect()->route('admin.courses.index');
}
public function edit(Course $course)
{
if(Gate::denies('edit_courses'))
{
return redirect (route('admin.courses.index'));
}
$instructors = User::whereHas('role', function ($query) {
$query->where('role_id', 2); })->get()->pluck('name');
return view('admin.course.edit')->with([
'course' => $course
]);
}
public function update(Request $request, Course $course)
{
$course->update($request->all());
if ($course->save()){
$request->session()->flash('success', $course->title . ' has been updated successfully.');
}else{
$request->session()->flash('error', 'There was an error updating ' . $course->title);
}
return redirect()->route('admin.courses.index');
}
public function show(Course $course)
{
return view('admin.course.show', compact('course'));
}
}
I am new to laravel so I would appreciate any help.
I have a departments table in db with id,name, and parent.The parent is the id that corresponds to the parent root.Now i have displayed the id(parent id) but i want to show the name of the department that correspond with this id.I have tried the query at the departmentcontroller ,index function but it gives me this error
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'departments' (SQL: select departments.id, departments.parent, departments.name from departments inner join departments on department.id = departments.parent where id = parent)
DepartmentController.php
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Department;
use App\User;
use Illuminate\Support\Facades\DB;
class DepartmentController extends Controller
{
public function usersdep($id)
{
$department = Department::with('users')->find($id);
return view('admin.page-users')->with('users', $department->users);
}
public function treeView()
{
$departments = Department::with('childs')->where('parent', 0)->get();
return view('admin.page',compact('departments'));
}
public function index()
{
//$departments = \App\Department::all();
//return view('admin.department')->with('departments', $departments);
return $departments = DB::table('departments')
->join('departments', 'department.id', '=', 'departments.parent')
->select('departments.id','departments.parent','departments.name')->where('id','=','parent')->get();
}
department.blade.php
#extends ('layouts.master')
#section('title')
Department Management | Admin
#endsection
#section('content')
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New department</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
</div>
<form action="/save-department" method="POST">
{{ csrf_field() }}
<div class="modal-body">
<div class="form-group">
<label for="recipient-name" class="col-form-label">Name</label>
<input type="text" class="form-control" name="name" id="recipient-name">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">ID</label>
<input type="text" class="form-control" name="id" id="recipient-id">
</div>
<div class="form-group">
<label for="recipient-name exampleFormControlSelect2" class="col-form-label">Parent ID</label>
<input type="text" class="form-control" placeholder="Choose the department parent id"name="parent" id="recipient-parent">
<select multiple class="form-control" name="parent" id="recipient-parent">
#foreach($departments as $department)
<option>{{ $department->parent }}</option>
#endforeach
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<div class="card-header">
<h4 class="card-title my-4 text-center font-weight-light"> Department Management </h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead class=" text-primary">
<th>Department</th>
<button type="button" class="btn btn-primary float-right" data-toggle="modal" data-target="#exampleModal" >Add</button>
<thead class=" text-primary">
<th>ID</th>
<th>Name</th>
<th>Parent ID</th>
<th>Edit</th>
<th>Delete</th>
</thead>
</thead>
<tbody>
#foreach($departments as $department)
<tr>
<td>{{ $department->id }}</td>
<td>{{ $department->name }}</td>
<td>{{ $department->parent }}</td>
<td>
Edit
</td>
<td>
<form action="{{ url('department-delete/'.$department->id) }}" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
See the Departments and Employees
</tbody>
</table>
</div>
</div>
</div>
</div>
#endsection
#section('scripts')
#endsection
web.php
<?php
use App\User;
use App\Department;
use App\Events\WebsocketDemoEvent;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
broadcast(new WebsocketDemoEvent('some data'));
return view('welcome');
});
Route::get('/page', function () {
return view('admin.page');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::group(['middleware' => ['auth','admin']], function () {
Route::get('/role-register','Admin\DashboardController#registered');
Route::delete('/role-delete/{id}', 'Admin\DashboardController#registerdelete');//delete user
Route::post('/save-user', 'Admin\DashboardController#store');
Route::get('/department', 'Admin\DepartmentController#index');
Route::post('/save-department', 'Admin\DepartmentController#store');
Route::get('/department-edit/{id}', 'Admin\DepartmentController#edit');//edit department
Route::put('/department-update/{id}', 'Admin\DepartmentController#update');
Route::delete('/department-delete/{id}', 'Admin\DepartmentController#delete');//delete department
Route::get('/page-users/{id}', 'Admin\DepartmentController#usersdep');//show users
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::get('/chats', 'ChatsController#index');//chats
Route::get('/messages', 'ChatsController#fetchMessages');//messages
Route::post('/messages', 'ChatsController#sendMessage');//messages
Route::get('/dashboard', 'Admin\DashboardController#dbcheck');//DATABASE
Route::get('/user-edit/{id}', 'HomeController#registeredit');
Route::get('/role-edit/{id}', 'Admin\DashboardController#registeredit');//edit user
Route::put('/role-register-update/{id}', 'Admin\DashboardController#registerupdate');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::get('store_image', 'StoreImageController#index');
Route::post('store_image/insert_image', 'StoreImageController#insert_image');
Route::get('store_image/fetch_image/{id}', 'StoreImageController#fetch_image');
Route::get('/page',array('as'=>'jquery.treeview','uses'=>'Admin\DepartmentController#treeView'));
Route::get('/pageusers', 'Admin\DepartmentController#usersdep');
Department.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Department extends Model
{
protected $table = 'departments';
protected $fillable = [
'name',
];
protected $primaryKey = 'id';
public function users()
{
// return $this->belongsTo(User::class);
return $this->hasMany(User::class,'department','id');
}
//category has childs
public function childs() {
return $this->hasMany('App\Department','parent','id') ;
/*
childs() method with hasMany relationship.
hasMany relationship in Laravel tell us that they have multiple childs.
Here I am creating relationship based on parent and each category has their parent if parent id is 0 it means it is root category.*/
}
}
create_departments_table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateDepartmentsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('departments', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->integer('parent');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('departments');
}
}
Alternative answer
Model
A Department model might be associated with one parent. To define this relationship, place a parent method on the model. The parent method should call the hasOne method and return its result:
class Department extends Model
{
protected $fillable = [
'name',
'parent_id',
];
public function parent()
{
return $this->hasOne(Department::class, 'id', 'parent_id');
}
}
Migration
Schema::create('departments', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->unsignedBigInteger('parent_id')->nullable();
$table->timestamps();
$table->foreign('parent_id')->references('id')->on('departments');
});
Usage
Once the relationship has been defined, you can retrieve the parent :
$departments = Department::get();
foreach ($departments as $department) {
if ($parent = $item->parent) {
dd($department->name, $parent->name);
}
else{
dd('This department is a parent')
}
}
You need to pass the correct department id.
public function index()
{
$departments = DB::table('departments')->select('departments.*')->get();
return view('admin.department', compact('departments'));
}
And view:
#foreach($departments as $department)
<tr>
<td>{{ $department->id }}</td>
<td>{{ $department->name }}</td>
#foreach($departments as $parent)
#if( $department->parent === $parent->id )
<td>{{ $department->name }}</td>
#endif
#endforeach
<tr>
#endforeach
Just define a relation in Department model
public function parentDepartment()
{
return $this->belongsTo(self::class, 'parent');
}
and in index method load it
public function index()
{
$departments = Department::with('parentDepartment')->get();
}
working with laravel 5.6 and in My comtroller I have two tables like vehicles and uploads.relationship with both two tables are,
Vehicle Model,
public function uploads()
{
return $this->hasMany(Upload::class);
}
and Upload Model,
public function vehicle()
{
return $this->belongsTo(Vehicle::class);
}
and I have following index function in My VehicleController,
$vehicles = Vehicle::with('uploads')
->orderBy('adtype','DESC')
->latest('updated_at')
->paginate(5);
return view('vehicles.index')->withVehicles($vehicles);
and index blade file is,
<form method="GET" action="{{ url('search') }}">
{{csrf_field()}}
<div class="row">
<div class="col-md-6">
<input type="text" name="search" class="form-control" placeholder="Search">
</div>
<div class="col-md-6">
<button class="btn btn-info">Search</button>
</div>
</div>
</form>
<br>
#forelse( $vehicles as $vehicule )
#if( $vehicule->uploads->count() > 0 )
<a href="{{ route('vehicles.show', $vehicule->id) }}">
#php
$upload = $vehicule->uploads->sortByDesc('id')->first();
#endphp
<div style="border-style: solid; background-color: {{ $vehicule->adtype === 1 ? '#FFEFD5' : '#FFFFFF' }} ">
<img src="/images/{{ $upload->resized_name }}" height="150" width="250"></a>
{{ Carbon\Carbon::parse($vehicule->created_at)->diffForHumans()}}
{{$vehicule->provincename}}
{{$vehicule->milage}}
</div>
<br>
<hr>
#endif
#empty
<td>No Advertisment to display.</td>
#endforelse
</div>
</div>
</div>
{{ $vehicles->links() }}
</div>
#endsection
my pagination is working fine, but in my index file I have search input using algolia. when I use keyword and click search button following error is occured,
(2/2) ErrorException
Method links does not exist. (View: C:\Users\banda\Desktop\ddddd\resources\views\vehicles\index.blade.php)
when I remove {{ $vehicles->links() }} in the view file it is working.
how can fix this problem?
Can you try
{{ $vehicles->render() }}
instead on ->links() ?
------ EDIT
Can you try passing the data to view like this?
$vehicles = Vehicle::with('uploads')
->orderBy('adtype','DESC')
->latest('updated_at')
->paginate(5);
return view('vehicles.index')->with(['vehicles' => $vehicles]);
and check?
I'm building a traveling app and the user has the possibility to edit their own departure date in case of a misplacement. At the moment, the user can edit the departure date from everyone. While it only should edit their own. Everything is working, but the update function where it should look for Auth::user();. Any idea how I should make this?
Here is the code:-
DepartureController.php
public function edit(LocationUser $LocationUsers)
{
return view('departure.edit', compact('LocationUsers'));
}
public function update(Request $request, LocationUser)
{
$LocationUsers = Auth::user();
$LocationUsers->update($request->all());
return redirect()->route('home', $LocationUsers)
->withSuccess('Departure updated!');
}
The web.php
//Backend Departure date
Route::get('/departure/create', 'DepartureController#create')->name('departure.create');
Route::post('/departure/create', 'DepartureController#store')->name('departure.store');
Route::get('/departure/edit/{LocationUsers}', 'DepartureController#edit')->name('departure.edit{id}');
Route::patch('/departure/edit/{LocationUsers}', 'DepartureController#update')->name('departure.update');
The edit.blade.php
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card card-default">
<div class="card-header">
{{$LocationUsers->departure_date}}
Update my departure
</div>
<div class="card-body">
#if (session('success'))
<div class="alert alert-dismissible alert-success">
{{ session('success') }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#endif
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form method="post" action="{{route('departure.update', $LocationUsers)}}">
{!!csrf_field().method_field('patch')!!}
<div class="form-group"> <!-- Date input -->
<label class="control-label" for="departure_date"></label>
Date
<input class="form-control" id="departure_date" name="departure_date"
placeholder="DD/MM/YYYY" type="text"/>
</div>
<input type="submit" class="btn btn-primary" value="Update departure">
</form>
</div>
</div>
</div>
</div>
</div>
The User model
public function daysUntilDeparture()
{
if ($this->location()->count() < 1) {
return "No departure date has been given";
}
$location = $this->location[0];
$userLocation = LocationUser::where('user_id', $this->id)
->where('location_id', $location->id)
->first();
$departure_date = $userLocation->departure_date;
return $departure_date->diffInDays(Carbon::now());
}
The LocationUser model
<?php
namespace App;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class LocationUser extends Model
{
const DATE_FORMAT = 'd-m-Y';
protected $fillable = ['departure_date', 'user_id'];
protected $dates = ['departure_date'];
protected $table = 'location_users';
public function user() {
return $this->belongsTo('\App\User', 'id', 'user_id');
}
public function location() {
return $this->hasOne('\App\Location', 'id', 'location_id');
}
public function setDepartureDateAttribute($date)
{
$this->attributes['departure_date'] = Carbon::createFromFormat(self::DATE_FORMAT, $date);
}
}
You can use
public function update(Request $request)
{
$date = Carbon::parse($request->departure_date);
$LocationUsers = LocationUser::where('user_id', Auth::id())->update(['departure_date' => $date]);
if($LocationUsers){
return redirect()->route('home', $LocationUsers)->withSuccess('Departure updated!');
}
}
i cant seem to fix my issue when i delete a task it redirects me to dashboard i can see in controller it is currently redirecting to /dashboard page however when i try to fix this it just errors out :/ i want it to acheive the same result the create redirection does
public function createTaskPage(Request $request, $slug) {
$project = Project::where('slug', $slug)->firstOrFail();
// Validate it has a body.
$validate = validator(
$request->toArray(), [
'task' => 'required',
]);
if ($validate->fails()) {
return response()->json([], 400);
}
$tasks = new Task;
$tasks->project_id = $project->id;
$tasks->body = $request->task;
$tasksCreate = Auth::user()->tasks()->save($tasks);
//return response()->json([], 201);
return redirect()->to('/project/' . $project->slug);
}
public function doDeleteTask($id) {
try {
$tasks = Task::where('user_id', Auth::user()->id)->findOrFail($id);
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $ex) {
return response()->json([], 404);
}
$tasks->delete();
//return response()->json([], 204);
return redirect()->to('/dashboard');
}
This is the Form where delete button is
<div class="col-md-3">
<div class="panel panel-default shadow">
<div class="panel-body">
<div class="row text-center">
<h4><strong>{{ str_limit(strip_tags($project->name), 20) }}</strong></h4>
<h5>{{ $project->created_at }}</h5>
</div>
<div class="row text-center" style="margin:5px;">
{{ ($project->description) }}
</div>
<div class="row text-center">
<form action="{{ url('/project/'.$project->id) }}" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-link btn-sm" onclick="return ConfirmDelete(this)" style="margin:5px;"><i class="fa fa-ban fa-3x" aria-hidden="true"></i></button>
<i class="fa fa-arrow-circle-o-right fa-3x" aria-hidden="true"></i>
</form>
</div>
</div>
</div>
This is my Delete route & create route
Route::delete('/task/{id}', 'TaskController#doDeleteTask'); // Delete a task
Route::post('/project/{slug}/task', 'TaskController#createTaskPage')->name('task');
If you have a project relation defined in tasks, you can do this:
public function doDeleteTask($id) {
try {
$tasks = Task::where('user_id', Auth::user()->id)->findOrFail($id);
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $ex) {
return response()->json([], 404);
}
$project = $tasks->project;
$tasks->delete();
return redirect()->to('/project/' . $project->slug);
}