ErrorException (E_ERROR) Undefined variable: group - php

when i search it will show error
ErrorException (E_ERROR) Undefined variable: group (View: C:\xampp\htdocs\ff\Laravel-Webboard-Workshop-master\resources\views\topic\index.blade.php) Previous exceptions Undefined variable: group (0)
in topic page at line of route('topic.create', $group->id) that is code about button new topic
view/topic/index.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-12">
#if (! Auth::guest())
<form action="/search_topic" method="get">
<button type="submit" class="btn btn-primary" style="float:right;">Search</button>
<a style="float:right;">
<input type="search" name="search" class="form-control" >
</a>
</form>
<br><br>
<div>
<a href="{{ url('/') }}" style="text-align:left;">
<button type="button" class="btn btn-default">
<span aria-hidden="true"></span>
Back to Home
</button>
</a>
<a href="{{ route('topic.create', $group->id) }}" style="float:right;"> <!--error-->
<button type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
New Topic
</button>
</a>
</div>
<br />
#endif
<div class="panel panel-default">
<div class="panel-heading" style="font-size: 18px;">
Group: {{ $group->title }}
</div>
<div class="panel-body">
<table class="table table-striped table-linkable table-hover">
<thead>
<tr>
<th class="text-center">Topic</th>
<th class="text-center">Posted By</th>
<th class="text-center">Posted At</th>
#if (! Auth::guest())
<th>Edit</th>
<th>Delete</th>
#endif
</tr>
</thead>
<tbody>
#foreach($topics as $topic)
<tr onclick="document.location.href = '{{ action('TopicController#show', $topic->id) }}'">
<td>{{ $topic->title }}</td>
<td class="text-center">{{ $topic->user['name'] }}</td>
<td class="text-center">{{ $topic->created_at->diffForHumans() }}</td>
#if (! Auth::guest())
<td>
#if (Auth::user()->id == $topic->user_id)
Edit
#endif
</td>
<td>
#if (Auth::user()->id == $topic->user_id)
<form method="post" class="delete_form" action="{{action('TopicController#destroy', $topic->id)}}">
{{csrf_field()}}
<input type="hidden" name="_method" value="DELETE" />
<button type="submit" class="btn btn-danger" onclick="return myFunction();">Delete</button>
<script>
function myFunction() {
if(!confirm("Are You Sure to Delete"))
event.preventDefault();
}
</script>
</form>
#endif
</td>
#endif
</tr>
#endforeach
</tbody>
</table>
<div class="text-center">
{!! $topics->links(); !!}
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
model Topic.php
<?php
namespace App;
use App\Group;
use App\Topic;
use Illuminate\Database\Eloquent\Model;
class Topic extends Model
{
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'title', 'body'
];
/**
* Get the Comments of a given topic.
*
* #return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments()
{
return $this->hasMany('App\Comment');
}
/**
* Get a user of a given topic
*
* #return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo('App\User');
}
public function group()
{
return $this->belongsTo('App\Group');
}
}
TopicController.php
<?php
namespace App\Http\Controllers;
use App\Comment;
use App\Topic;
use App\Group;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
class TopicController extends Controller
{
public function search(Request $request)
{
$search = $request->get('search');
//$groups = DB::table('groups')->where('title', 'like', '%'.$search.'%')->paginate(5);
$topics = Topic::with('user')->where('title', 'like', '%'.$search.'%')->paginate(5);
return view('topic.index', ['topics' => $topics] );
}
}
How should i do to fix this bug for search in my topic page??

Related

Laravel [9] html sometimes does not render properly

Actually this problem i noticed a have few weeks ago.
I using Docker for Windows and laravel running on docker.
I tried using local and remote database, but nothing has changed.
What is the problem? I cant detect anything.
This page is look like good rendered. But if i change page or reload, any place is look like this in page. I tried some things but didnt work.
Not every time, just sometimes :/
list.blade.php
#extends('admin.layouts.master')
#section('title', 'Tüm Siparişler')
#section('content')
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row mb-2">
<div class="col-sm-4">
<div class="search-box me-2 mb-2 d-inline-block">
<div class="position-relative">
<form method="GET" action="{{ route('admin_order_status', $status) }}">
<input type="text" name="search" class="form-control"
value="{{ $search }}" placeholder="Arama...">
<i class="bx bx-search-alt search-icon"></i>
</form>
</div>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table align-middle table-nowrap table-check">
<thead class="table-light">
<tr>
<th style="width: 20px;" class="align-middle">
<div class="form-check font-size-16">
<input class="form-check-input" type="checkbox" id="checkAll">
<label class="form-check-label" for="checkAll"></label>
</div>
</th>
<th class="align-middle">ID</th>
<th class="align-middle">Ürün</th>
<th class="align-middle">Müşteri</th>
<th class="align-middle">Fiyat</th>
<th class="align-middle">Sonraki ödeme tarihi</th>
<th class="align-middle">Durum</th>
</tr>
</thead>
<tbody>
#foreach ($orders as $item)
<tr>
<td>
<div class="form-check font-size-16">
<input class="form-check-input" type="checkbox"
id="orderidcheck{{ $item->order_id }}">
<label class="form-check-label"
for="orderidcheck{{ $item->order_id }}"></label>
</div>
</td>
<td>
<a href="{{ route('admin_order_view', $item->order_id) }}"
class="text-body fw-bold">
{{ $item->order_id }}
</a>
</td>
<td>
<a href="{{ route('admin_order_view', $item->order_id) }}"
class="text-body fw-bold">
{{-- #lang("admin/orders.type.{$item->data->product_name}") --}}
{{ $item->data->product_name }}
</a>
</td>
<td>
<a href="{{ route('admin_users_summary', $item->user_id) }}">
{{ $item->first_name }} {{ $item->last_name }}
</a>
</td>
<td>
{{ $item->amount }} ₺
</td>
<td class="fw-bold">
#if ($item->next_paid_at)
{{ Carbon\Carbon::parse($item->next_paid_at) }}
#else
-
#endif
</td>
<td>
<span
class='badge badge-pill bg-{{ config("enums.order_status_color.$item->status") }} font-size-12'>
#lang("admin/orders.$item->status")
</span>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
{!! $orders->withQueryString()->links() !!}
</div>
</div>
</div>
</div>
#endsection
Controller.php
class OrdersController extends Controller
{
public function indexByStatus(Request $request, string $status = 'all')
{
$search = $request->get('search');
$orders = Order::query();
$orders = $orders->join('users', 'users.id', '=', 'orders.user_id');
$orders = $orders->select([
'users.id as user_id',
'users.first_name',
'users.last_name',
'orders.id as order_id',
'orders.amount',
'orders.data',
'orders.payment_method',
'orders.invoice_id',
'orders.status',
'orders.next_paid_at',
]);
if ($search) {
if ($status != 'all') {
$orders->where('orders.status', $status);
}
$orders->where(function ($q) use ($search) {
return
$q->orWhere('users.first_name', 'LIKE', "%$search%")
->orWhere('users.last_name', 'LIKE', "%$search%")
->orWhere('orders.data', 'LIKE', "%$search%");
});
} else {
if ($status != 'all') {
$orders->where('orders.status', $status);
}
}
$orders = $orders->orderByDesc('orders.created_at');
$orders = $orders->paginate(10);
return view(
'admin.orders.allorders',
[
'orders' => $orders,
'search' => $search,
'status' => $status,
]
);
}
}
Model.php
class Order extends Model
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array<int, string>
*/
protected $fillable = [
'status',
'payment_method',
'billing_period',
'data',
'user_id',
'invoice_id',
'amount',
'next_paid_at',
];
/**
* The attributes that should be hidden for serialization.
*
* #var array<int, string>
*/
protected $hidden = [];
/**
* The attributes that should be cast.
*
* #var array<string, string>
*/
protected $casts = [
'data' => 'object',
'next_paid_at' => 'timestamp',
'created_at' => 'timestamp',
'updated_at' => 'timestamp'
];
public function user()
{
return $this->hasOne(User::class, 'id', 'user_id');
}
}

Laravel 8 Call to undefined method Illuminate\Database\MySqlConnection::tabel()

its laravel 8 course im getting this error while using query builder but with ORM its perfectly run well. when i comment this code and use another method for getting data with query builder in AllCat() method DB::table is running perfectly
Category Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Category;
use Auth;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class CategoryController extends Controller
{
public function AllCat(){
$categories = DB::tabel('categories')
->join('users','categories.user_id','users.id')
->select('categories.*','users.name')
->latest()->paginate(5);
// $categories = Category::latest()->paginate(5);
//$categories = DB::table('categories')->latest()->paginate(5);
return view('admin.category.index',compact('categories'));
}
public function AddCat(Request $request){
$validated = $request->validate([
'category_name' => 'required|unique:categories|max:255',
],
[
'category_name.required' => 'Please Input Category Name',
'category_name.max' => 'Category Less Then 255Chars',
]);
Category::insert([
'category_name' => $request->category_name,
'user_id' => Auth::user()->id,
'created_at' => Carbon::now()
]);
// $category = new Category;
// $category->category_name = $request->category_name;
// $category->user_id = Auth::user()->id;
// $category->save();
// $data = array();
// $data['category_name'] = $request->category_name;
// $data['user_id'] = Auth::user()->id;
// DB::table('categories')->insert($data);
return redirect()->back()->with('success','Category Inserted Successfull');
}
}
Index.blade.php
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
All Category<b> </b>
</b>
</h2>
</x-slot>
<div class="py-12">
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="card">
#if(session('success'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>{{ session('success') }}</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
#endif
<div class="card-header"> All Category
</div>
<table class="table">
<thead>
<tr>
<th scope="col">SL No</th>
<th scope="col">Category Name</th>
<th scope="col">User</th>
<th scope="col">Created At</th>
</tr>
</thead>
<tbody>
<!-- #php($i = 1) -->
#foreach($categories as $category)
<tr>
<th scope="row">{{ $categories->firstItem()+$loop->index }}</th>
<td>{{ $category->category_name }}</td>
<td>{{ $category->name }}</td>
<td>
#if($category->created_at == NULL)
<span class="text-danger">No Date Set</span>
#else
{{ Carbon\Carbon::parse($category->created_at)->diffforHumans() }}</td>
#endif
</tr>
#endforeach
</tbody>
</table>
{{ $categories->links() }}
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">Add Category</div>
<div class="card-body">
<form action="{{ route('store.category') }}" method="POST">
#csrf
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Category Name</label>
<input type="text" name="category_name" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
#error('category_name')
<span class="text-danger">{{ $message }}</span>
#enderror
</div>
<button type="submit" class="btn btn-primary">Add Category</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Can you tell me what is wrong here
are you sure it is DB::tabel and not DB::table ?? It surely has to be DB::table

Laravel - Data not pulling through to form

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 created fetching page using laravel 5.2, the data are displaying in table

I created fetching page using laravel 5.2, the data are displaying in table and I gave dropdown option for each row for deleting and view the data. when i click on delete its showing error
NotFoundHttpException in C:\xampp\htdocs\opennGTS\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php line 161:
Actually I did routing and all. Can anyone tell me why am getting this error?. My view page is giving below.
#extends('app')
#section('content')
<div class="templatemo-content-wrapper">
<div class="templatemo-content">
<ol class="breadcrumb">
<li><font color="green">Home</font></li>
<li class="active">Vehicle information</li>
</ol>
<h1>View/Edit Vehicle information</h1>
<p></p>
<div class="row">
<div class="col-md-12">
<div class="table-responsive" style="overflow-x:auto;">
<table id="example" class="table table-striped table-hover table-bordered" bgcolor="#fff8dc">
<h3>Select a Vehicle :</h3>
<thead>
<tr>
<th>Vehicle ID</th>
<th>Unique ID</th>
<th>Description</th>
<th>Equipment Type</th>
<th>SIM Phone</th>
<th>Server ID</th>
<th>Ignition State</th>
<th>Expecting ACK</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach($devices as $device)
<tr>
<td>{{ $device->vehicleID }}</td>
<td>{{ $device->uniqueID }}</td>
<td>{{ $device->description }}</td>
<td>{{ $device->equipmentType }}</td>
<td>{{ $device->simPhoneNumber }}</td>
<td></td>
<td>
#if(#$device->ignitionIndex == '0')
OFF
#else
ON
#endif
</td>
<td>{{ $device->expectAck }}</td>
<td>
#if($device->isActive == '1')
Yes
#else
No
#endif
</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-info">Action</button>
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li data-toggle="modal" data-target="#acceptModal" data-bookingid="{{ $device->vehicleID }}">View/ Edit
</li>
<li>Delete</li>
</ul>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
{{--{!! $results->appends(['sort' => $sort])->render() !!}--}}
{{$devices->links()}}
</div>
</div>
</div>
</div>
</div>
{{--{!! $device->links()!!}--}}
</br>
<h4>Create a new Vehicle</h4>
<form role="form" method="POST" action="{{ url('vehicleAdmin') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-md-6 margin-bottom-15">
<input type="text" class="form-control" name="vehicleID" value="{{ old('vehicleID') }}" placeholder="Enter vehicle ID">
</div>
<div class="row templatemo-form-buttons">
<div class="submit-button">
<button type="submit" class="btn btn-primary">New</button>
</div>
</div>
</div>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
#endsection
Controller Page is
<?php
namespace App\Http\Controllers;
use Mail;
use Illuminate\Support\Facades\DB;
use App\Device;
use App\Http\Requests\createUserRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Illuminate\Pagination\Paginator;
class VehicleController extends Controller
{
public $type = 'Device';
// public function getIndex()
// {
// $users = DB::select('select * from user where', [1]);
//
// return view('user.userAdmin', ['user' => $users]);
// }
public function getIndex()
{
// $user = DB::table('user')->get();
// $devices = Device::table('device')->simplepaginate(15);
$devices = DB::table('device')->simplePaginate(4);
return view('vehicle.vehicleAdmin')->with('devices', $devices);
}
public function vehicleInsert()
{
$postUser = Input::all();
//insert data into mysql table
$data = array('vehicleID'=> $postUser['vehicleID']
);
// echo print_r($data);
$ck = 0;
$ck = DB::table('device')->Insert($data);
//echo "Record Added Successfully!";
$devices = DB::table('device')->simplePaginate(10);
return view('vehicle.vehicleAdmin')->with('devices', $devices);
}
public function delete($id)
{
DB::table('device')->where('vehicleID', '=', $id)->delete();
return redirect('vehicleAdmin');
}
}
and route is
Route::any('vehicleAdmin', 'VehicleController#getIndex');
Route::any('vehicle/delete/{id}', 'VehicleController#delete');
I think it's better to specify your route method use delete instead of any.
Route::delete('vehicle/delete/{id}', 'VehicleController#delete');
It may work.

Laravel 5.1 Object of class Illuminate\Database\Eloquent\Relations\HasMany could not be converted to string

I have problem with my laravel 5.1 error Object of class Illuminate\Database\Eloquent\Relations\HasMany could not be converted to string when i click delete
GalleryController.php
public function deleteGallery($id)
{
//load the gallery
$currentGallery = Gallery::findOrfail($id);
// check ownership
if ($currentGallery->created_by != Auth::user()->id) {
abort('403','You are not allowed to delete this gallery');
}
// get the images
$images = $currentGallery->images();
// delete the images
foreach ($currentGallery->$images as $image) {
unlink(public_path($image->file_path));
}
// delete the DB records
$currentGallery->images()->delete();
$currentGallery->delete();
return redirect()->back();
}
Route.php
Route::get('gallery/delete/{id}','GalleryController#deleteGallery');
Model Gallery.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Gallery extends Model
{
protected $table = 'gallery';
public function images()
{
return $this->hasMany('App\Image');
}
}
Model Image.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class image extends Model
{
protected $fillable = ['gallery_id', 'file_name', 'file_size', 'file_mime', 'file_path',
'created_by'];
public function gallery()
{
return $this->belongsTo('App\Gallery');
}
}
Views gallery.blade.php
#extends('master')
#section('content')
<div class="row">
<div class="col-md-12">
<h1>My Gallery</h1>
</div>
</div>
<div class="row">
<div class="col-md-8">
#if ($galleries->count() > 0)
<table class="table table-striped table-bordered table-responsive">
<thead>
<tr class="info">
<th>Name of the gallery</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach($galleries as $gallery)
<tr>
<td>{{$gallery->name}}
<span class="pull-right">
{{ $gallery->images()->count() }}
</span>
</td>
<td>View /
Delete
</td>
</tr>
#endforeach
</tbody>
</table>
#endif
</div>
<div class="col-md-4">
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form" method="POST" action="{{url('gallery/save')}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<input type="text" name="gallery_name"
id="gallery_name" placeholder="Name of the gallery"
class="form-control"
value="{{ old('gallery_name')}}" />
</div>
<button class="btn btn-primary">Save</button>
</form>
</div>
</div>
#endsection
In the gallery controller you don't need to get the images since you’re not using the variable anywhere else. Hence remove the lines
// get the images
$images = $currentGallery->images();
Just have the foreach be as
// delete the images
foreach ($currentGallery->images as $image) {
unlink(public_path($image->file_path));
}
please note use of $currentGallery->images
Change:
$images = $currentGallery->images();
To:
$images = $currentGallery->images;

Categories