Obviously this doesn't work since they have the same name. How do I go about fixing this? Thanks in advance.
Heres the rest of my ItemsController for the context they're needed.
<?php
namespace App\Http\Controllers;
use App\Item;
// use Request;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\ItemRequest;
class ItemsController extends Controller
{
public function __construct()
{
$this->middleware('auth', ['except' => ['index', 'show']]);
}
public function index()
{
$items = Item::all();
// $items = Item::latest('created_at')->get();
return view('items.index', compact('items'));
}
public function show(Item $item)
{
return view('items.show', compact('item'));
}
public function create()
{
//Potentially use something like this for charging for ad
// $cost = str_word_count(desc);
return view('items.create');
}
public function store(ItemRequest $request)
{
$input = Request::all();
Item::create($input);
return redirect('items');
}
public function addPhoto(Request $request)
{
// $this->validate($request, [
// 'photo' => 'require|mimes:jpg,jpeg,png,bmp'
// ]);
$file = $request->file('photo');
$name = time().$file->getClientOriginalName();
$file->move('public/items_add/photos', $name);
//needs to change from first() to 'current()'
$item = Item::first();
// $item = Item::find($item->id);
//Add $item into function arguments and test with line below (actually try using $id not $item)
// $item = Item::findOrFail($item);
$item->photos()->create(['path'=>"public/items_add/photos/{$name}"]);
return 'Done';
}
}