if im not mistaken, Project.php doesnt need to write anything right ? thankyou in advance, im new in laravel
Where did I go wrong in uploading file
// ProjectController
public function store(Request $request)
{
$user = Auth::user()->id;
if($request->hasFile('project_file'))
{
$filename = $request->project_file->getClientOriginalName();
$request->project_file->storeAs('public/project_file',$filename);
$project = Project::create([
'user_id' => $user,
'project_title' => $request->project_title,
'project_scope' => $request->project_scope,
'project_description' => $request->project_description,
'project_type' => $request->project_type,
'project_duration' => $request->project_duration,
'project_slot' => $request->project_slot,
'project_file' => $filename,
'project_status' => 1,
]);
}
return redirect('teamfinder/project')->with('status','Your project has been created');
}
//projects
public function up()
{
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->string('project_title');
$table->string('project_scope');
$table->string('project_description');
$table->string('project_type');
$table->integer('project_duration');
$table->integer('project_slot');
$table->string('project_file');
$table->string('project_status');
$table->timestamps();
});
}
// View
<form action="{{ action('TeamFinder\ProjectController@store') }}" method="post" class="form-bordered" enctype="multipart/data">
@csrf
<div class="form-group">
<label>Project Title</label>
<input type="text" name="project_title" class="form-control">
</div>
<div class="form-group">
<label>Project Scope</label>
<input type="text" name="project_scope" class="form-control">
</div>
<div class="form-group">
<label>Project Description</label>
<input type="text" name="project_description" class="form-control">
</div>
<div class="form-group">
<label>Project Type</label>
<select name="project_type" class="form-control">
<option value="0">-- Please select project type -- </option>
<option value="1">One Time</option>
<option value="2">Recurring</option>
</select>
</div>
<div class="form-group">
<label>Project File</label>
<input type="file" name="project_file" class="form-control">
</div>
<div class="form-group">
<label>Project Slot</label>
<input type="numeric" name="project_slot" class="form-control">
</div>
<div class="form-group">
<label>Project Duration</label>
<input type="numeric" name="project_duration" class="form-control">
</div>
<!-- END Labels on top Form Content -->
</div>
<!-- END Labels on top Form Block -->
<center>
<div class="form-group form-actions ">
<button type="submit" class="btn btn-effect-ripple btn-primary">Submit</button>
<button type="reset" class="btn btn-effect-ripple btn-danger">Reset</button>
</div>
</center>
</form>
Do you see any errors when you submit the form?
I would suggest that in Project you have not updated the private $fillable= [] with all the fields you are saving. On another hand do not use action('TeamFinder\ProjectController@store') in the form action. Go to the web.php with all your Routes and create a route Route::post('/form/submit', 'TeamFinder\ProjectController@store'); and might give a ->name('form-submit'); then in the form itself in the blade you can use route('form-submit') or the full path 'form/submit'.
Also you have an extra div in your blade.
You are missing the form validation in the controller.
In the blade change to enctype="multipart/form-data"
Just a semantic mistake but $user = \Auth::user()->id; the variable is called wrongly. You would expect that it will have the full user object but you have only the id. Should be called $userId or $user = \Auth::user(); then later $user->id
Please or to participate in this conversation.