hello m working in a project in which an admin and user have their own home pages, admin adds the files and assigns the user id to the file, I wants that when user login then those file in which his id assigned he get that file or that file shown to him ,,, but in my code it shows error that: Undefined variable: data (View: D:\xampp\htdocs\laravel\webpro\resources\views\home.blade.php) ,,,, code of homecontroller:
class HomeController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('home');
}
public function show($id)
{
$data = File::findOrFail($id);
$files = \DB::table('files')->get();
return view('home', compact('data', 'files'));
}
and this is home.blade.php(where to show the file):
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">User's View</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
You are logged in!
</div>
<!---->
<div class="form-group">
<label for="ShowFile">File</label>
<input type="file" name="file" class="form-control-file">
<img src="{{ URL::to('/') }}/files/{{ $data->file }}" width="100" />
<input type="hidden" name="hidden_file" value="{{ $data->file }}" />
</div>
<!---->
</div>
</div>
</div>
</div>
how to resolve it?