I created a simple Laravel application on Plesk.
I tried to store some PDF files in public/storage/pdf, and I saved the file path in the database as a VARCHAR.
However, the PDF file is not being stored in that folder.
Please help me — I am new to web hosting and Laravel.
//ivocontorller <?php namespace AppHttpControllers; use IlluminateHttpRequest; use AppModelsivo_input; use IlluminateSupportFacadesStorage; // Import Storage facade for file handling class IvoController extends Controller { public function index() { $ivo=ivo_input::all(); return view('IVO.bootstaps',['ivo'=>$ivo]); // Assuming you have a view named 'ivo.index' // Retrieve all records from the ivo_input tableS } public function show() { $ivo=ivo_input::all(); return view('IVO.show',['ivo'=>$ivo]); // Assuming you have a view named 'ivo.index' // Retrieve all records from the ivo_input tableS } public function create(){return view('IVO.create'); // Assuming you have a view named 'ivo.create' } public function store(Request $request) { // Validate the request inputs $data = $request->validate([ 'description' => 'required', 'type' => 'required', 'job_title' => 'required', 'department' => 'required', 'Jd_pdf' => 'required', // PDF only, max 2MB ]); // Store the PDF and get its path $path = $request->file('Jd_pdf')->store('storage/pdf', 'public'); //dd($path); // Debugging line to check the file path // Add the file path to the data array $data['Jd_pdf'] = $path; // Create the new record in the database ivo_input::create($data); // Redirect to index route return redirect(route('ivo.index')); } public function edit( ivo_input $ivo)//kena letak model sama dengan dia punya variable yang di pass { //return view('ivo.edit', ['ivo' => $ivo]); //ivo edit ada value pass the value return view('IVO.edit', ['ivo' => $ivo]); //ivo edit ada value pass the value } public function update(Request $request, ivo_input $ivo) { $data= $request->validate([ 'description' => 'required', 'type' => 'required', 'job_title' => 'required', 'department' => 'required', ]); $ivo->update($data); // Update the record in the ivo_input table return redirect(route('ivo.index'))->with('success','Vacancy Updated Successffully'); // Redirect to the index route } public function destroy(ivo_input $ivo) { // Delete the file from storage if it exists if ($ivo->Jd_pdf && Storage::disk('public')->exists($ivo->Jd_pdf)) { Storage::disk('public')->delete($ivo->Jd_pdf); } $ivo->delete(); // Delete the record from the ivo_input table return redirect(route('ivo.index'))->with('success', 'Vacancy Deleted Successfully'); // Redirect to the index route } }
<ivo_input>(model controller)
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentFactoriesHasFactory;
class ivo_input extends Model //nama kena sama dengan nama table dalam database, kalau tak sama kena guna protected $table
{
use HasFactory;protected $table = 'ivo_tables'; // guna ni kalau nama model lain dengan nama table
protected $fillable = [
'description',
'type',
'job_title',
'department',
'Jd_pdf',
];
}
viewer<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round|Open+Sans">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"><script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script><link rel="stylesheet" href="{{ asset('/resources/css/bootsrap.css') }}">
{{-- Rasa tak perlu import pun sebab bootstrap tu dah siap ada --}}
{{-- nanti nak letak js atau css masuk dalam public folder --}}
{{-- ni tak boleh odan, rasa sebab bukan dalam file public tu dia tak boleh nak access, simpan dalam public okay ? --}}{{-- <link rel="stylesheet" href="../resources/css/bootsrap.css"> --}}
{{-- <div class="btn btn-primary">asdasdasd</div> --}}
<script src="{{ url('/resources/js/template.js') }}"></script>
</head>
<body>
<div class="container-lg">
<div class="table-responsive">
<div class="table-wrapper">
<div class="table-title">
<div class="row">
<div class="col-sm-8"><h2>VACANCY OPENING <b>Details</b></h2></div>
<div class="col-sm-4">
<button type="button" class="btn btn-info add-new" onclick="window.location.href='{{ route('ivo.create') }}'">
<i class="fa fa-plus"></i> Add New
</button></div>
</div>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>Job Title</th>
<th>Job Description</th>
<th>Job Position</th>
<th>Status</th>
<th>Department</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>@foreach($ivo as $ivos)
<tr>
<td>{{ $ivos->job_title }}</td>
<td> <a href="{{ asset($ivos->Jd_pdf) }}" target="_blank">View PDF</a></td>
<td>{{ $ivos->description }}</td>
<td>{{ $ivos->type }}</td>
<td>{{ $ivos->department }}</td>
<td>
<a href='{{ route('ivo.create') }}'class="add" title="Add" data-toggle="tooltip"><i class="material-icons"></i></a><a href="{{ route('ivo.edit', $ivos->id) }}" class="edit" title="Edit" data-toggle="tooltip"><i class="material-icons"></i></a>
{{-- <a class="add" title="Add" data-toggle="tooltip"><i class="material-icons"></i></a>
<a class="edit" title="Edit" data-toggle="tooltip"><i class="material-icons"></i></a> --}}
</td>
<td>
<form method="post" action="{{ route('ivo.destroy', $ivos->id) }}">
@csrf
@method('delete')
<button type="submit" class="delete" title="Delete" data-toggle="tooltip" style="background: none; border: none; margin: 0%;">
<i class="material-icons"></i>
</button>
</form></td>
</tr>
@endforeach
{{-- <tr>
<td>John Doe</td>
<td>Administration</td>
<td>(171) 555-2222</td>
<td></td>
<td>
<a class="add" title="Add" data-toggle="tooltip"><i class="material-icons"></i></a>
<a class="edit" title="Edit" data-toggle="tooltip"><i class="material-icons"></i></a>
<a class="delete" title="Delete" data-toggle="tooltip"><i class="material-icons"></i></a>
</td>
</tr> --}}</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
i managed to insert data into database but not able to store in pdf file.