How to change the name of the downloaded file when editing in Laravel?

if (isset($article) && isset($article->id)) <option value=”0″ >Publish</option> <option value=”1″ >No publish</option> @else <option value=”0″ selected disabled>No publish</option> <option value=”1″ disabled>Publish</option> @endif <img src=”” alt=””> <input type=”file” name=”image_path” /> function upload(Request $request){ $image = $request->file(‘image_path’); $new_name = rand() . ‘.’ . $image->getClientOriginalExtension(); $image->move(public_path(‘images’), $new_name); return $new_name; } public function update(Request $request, Article $article) { $article->update($request->except(‘slug’)); $article->categories()->detach();…

Laravel Undefined variable when no entry is found in a table

MenusController.php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Menu; public function index(){ $menus = Menu::orderBy(‘created_at’ , ‘asc’)->get(); return view(‘menus.index’)->with(‘menus’ , $menus); } views/menus/index.blade.php @if(count($menus) > 0) @foreach($menus as $menu) <h4></h4> @endforeach @else <p>No menu categories</p> @endif So I have a table in my database called “menus” and one of the columns is called “category”. When I have…