Posting data over post route - Page expired - laravel

I'm attempting to post data to my database using Laravel, but I can't seem to do so. The post route sends to a an expired page.
Here is the route
Route::post('/expenses', 'PropertyExpenseController#store')->middleware('auth');
This is the create and store functions which render the form, and process the form.
public function create($id){
$property = PropertyAdvert::where('id', $id)->first();
return view('/pages/expenses/create', compact('property'));
}
public function store(Request $request){
$PropertyExpenses = PropertyExpenses::create([
"property_id" => $request->property_id,
"user_id" => Auth::user()->id,
"expenseDescription" => $request->description,
"cost" => $request->amount,
"date" => $request->date,
"category" => $request->category
]);
return "Expense Log";
}
This is the view page, where the form is loaded. All the data is got in the controller via the names on the input elements.
<form method="POST" action="/expenses">
<span name="property_id" class="text-muted">{{$property->id}}</span>
<div class="row mt-4 justify-content-center">
<div class="col-md-6">
<label class="" for"description">Expense Description<label>
</div>
</div>
<div class="row form-group justify-content-center">
<div class="col-md-4">
<input class="form-control " type="text" name="description">
</div>
</div>
<div class="row mt-4 justify-content-center">
<div class="col-md-6">
<label for"amount">Amount<label>
</div>
</div>
<div class="row form-group justify-content-center">
<div class="col-md-4 input-group">
<span class="input-group-addon mr-1 mt-1">€</span>
<input class="form-control" type="text" name="amount">
</div>
</div>
<div class="row mt-4 justify-content-center">
<div class="col-md-6">
<label for"category">Category<label>
</div>
</div>
<div class="row form-group justify-content-center">
<div class="col-md-4">
<select class="form-control" id="category" name="category">
<option>Mortgage Payment</option>
<option>Maintainence</option>
<option>Management Fee</option>
</select>
</div>
</div>
<div class="row mt-4 justify-content-center">
<div class="col-md-6">
<label for"description">Date<label>
</div>
</div>
<div class="row form-group justify-content-center">
<div class="col-md-4">
<input class="form-control" type="date" name="date">
</div>
</div>
<input type="submit" class="btn btn-primary" value="Log Expense">
</form>
THis is the model, with the fillable array.
class PropertyExpense extends Model
{
protected $fillable = ['property_id'. 'user_id', 'expenseDescription', 'cost', 'date', 'category'];
public function property(){
return $this->belongsTo('App\PropertyAdverts');
}
}

In your form, you need a CSRF Token field.
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Read more here.

Related

Laravel form submit unsuccessful returns blank page instead of redirect home

I have a laravel form to create a new product entry in a database on submit, am supposed to be redirected back but I get a completely blank page without any errors. There is no new entry in my database when I check. The form is made up of various text fields, an image URL, and a multi-selected Image URL
please this is my blade template
<form method="POST" action="{{ route('products.store') }}" enctype="multipart/form-data">
<h4 class="card-title">Create Product</h4><br><br>
#csrf
<div class="row">
<div class="col">
<div class="row mbr-1">
<label for="example-text-input" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-6">
<input name="name" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input"
class="col-sm-2 col-form-label">Category</label>
<div class="col-sm-6">
<input name="name" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Price</label>
<div class="col-sm-6">
<input name="catchy_title" class="form-control" type="number"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Status</label>
<div class="col-sm-6">
<input name="status" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Product
Description</label>
<div class="col-sm-8">
<textarea id="elm1" name="long_description" placeholder="Please enter a vivid description of the product"></textarea>
</div>
</div>
<!-- end row -->
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Tags</label>
<div class="col-sm-6">
<input name="tags" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Estimated
Delivery
Time</label>
<div class="col-sm-6">
<input name="estimated_delivery_time" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Available
Quantity</label>
<div class="col-sm-6">
<input name="available_quantity" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Colors</label>
<div class="col-sm-6">
<input name="colors" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Supplier's
Name</label>
<div class="col-sm-6">
<input name="supplier_name" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Supplier's
Contact</label>
<div class="col-sm-6">
<input name="supplier_contact" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Video Url /
Link</label>
<div class="col-sm-6">
<input name="video_description" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Primarry
Image</label>
<div class="col-sm-6">
<input name="primary_image" accept="image/*" class="form-control"
type="file" id="image">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label"> Primary Image
Preview</label>
<div class="col-sm-6">
<img id="showImage" class="" width="300px"
src="{{ !empty($Product->image) ? url('upload/products/' . $product->image) : url('upload/no_image.jpg') }}"
alt="Hero image">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Add Other
Images</label>
<div class="col-sm-6">
<input name="multi_image[]" accept="image/*" class="form-control"
type="file" id="image" multiple="">
</div>
</div>
<!-- end row -->
</div>
</div>
<input type="submit" class="btn btn-info waves-effect waves-light"
value="Create Product">
</form>
and this is my store function
public function store(Request $request)
{
if ($request->file('image')) {
$image = $request->file('image');
$name_gen = hexdec(uniqid()).'.'.$image->getClientOriginalExtension(); // 3434343443.jpg
Image::make($image)->resize(523,605)->save('upload/home_about/'.$name_gen);
$save_url = 'upload/products/'.$name_gen;
$this->validate($request, [
'name' => $request->name,
'category' => $request->category,
'price' => $request->price,
'description' => $request->description,
'status' => $request -> status,
'tags' => $request -> tags,
'estimated_delivery_time' => $request->estimated_delivery_time,
'available_quantity' => $request->available_quantity,
'colors' => $request->colors,
'supplier_name' => $request->supplier_name,
'supplier_phone' => $request->supplier_phone,
'video_description' => $request->video_description,
'primary_image' => $save_url,
'other_images' => $save_url,
]);
$notification = array(
'message' => 'Product created successfully',
'alert-type' => 'success'
);
return redirect()->back()->with($notification);
}
Please what am I doing wrong?
thank you for taking some time to review
you are validating the request but not saving it to database.
after the validation and before the return you should do like this to save in database.
$item=new YOUR_MODEL_NAME:
$item->name => $request->name,
$item->category => $request->category,
$item->price => $request->price,
$item->description => $request->description,
$item->status => $request -> status,
$item->tags => $request -> tags,
$item->estimated_delivery_time => $request->estimated_delivery_time,
$item->available_quantity => $request->available_quantity,
$item->colors => $request->colors,
$item->supplier_name => $request->supplier_name,
$item->supplier_phone => $request->supplier_phone,
$item->video_description => $request->video_description,
$item->primary_image => $save_url,
$item->other_images => $save_url,
$item->save();
$this->validate($request, [
'name' => $request->name,
'category' => $request->category,
'price' => $request->price,
'description' => $request->description,
'status' => $request -> status,
'tags' => $request -> tags,
'estimated_delivery_time' => $request->estimated_delivery_time,
'available_quantity' => $request->available_quantity,
'colors' => $request->colors,
'supplier_name' => $request->supplier_name,
'supplier_phone' => $request->supplier_phone,
'video_description' => $request->video_description,
'primary_image' => $save_url,
'other_images' => $save_url,
]);
In the snippet above you're performing the validation, but I don't see a request to persist the data to your database in your store() function.
It's recommended to utilize the functionality provided by the framework when checking for request input presence. These functions usually provide quality-of-life aspects such as checking for multiple input presence and conditional callbacks as well.
https://laravel.com/docs/9.x/requests#determining-if-input-is-present
if ($request->has('name')) {
//
}
You should also be calling the validate() method on $request, not $this.
First, I'd like to recommend that you utilize a Form Request
https://laravel.com/docs/9.x/validation#form-request-validation
Second, use the validated data and mass assignment when storing the new model. If the validated data structure is not 1:1 with the table schema, you could always assign the values manually but this will result in a bloated controller. One possible solution is to utilize a DTO (Data Transfer Object) and provide the validated() array to the DTO when using mass assignment.
// Without DTO
Model::create($modelStoreRequest->validated());
// With DTO
$DTO = new MyDTO($modelStore$request->validated())->toArray();
Model::create($DTO);
Note that if the incoming request fields do not pass the given validation rules Laravel will automatically redirect the user back to their previous location. In addition, all of the validation errors and request input will automatically be flashed to the session.
Try to be specific, pass route where you want to redirect like below:
return redirect()->route('route-name-here')->with($notification);

Must provide source or customer. laravel 8 stripe payment gateway

Must provide source or customer. laravel 8 stripe payment gateway
StripeController
public function stripe()
{
return view('stripe');
}
public function stripePost(Request $request)
{
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
Stripe\Charge::create ([
"amount" => 100*100,
"currency" => "INR",
"source" => $request->stripeToken,
"description" => "This payment is testing purpose of websolutionstuff.com",
]);
Session::flash('success', 'Payment Successful !');
return back();
}
stripe.blade.php
<div class="container">
<div class="row">
<h3 style="text-align: center;margin-top: 40px;margin-bottom: 40px;">Stripe Payment</h3>
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default credit-card-box">
<div class="panel-heading">
<div class="row">
<h3>Payment Details</h3>
<div>
{{-- <img class="img-responsive pull-right" src="http://i76.imgup.net/accepted_c22e0.png"> --}}
</div>
</div>
</div>
<div class="panel-body">
#if (Session::has('success'))
<div class="alert alert-success text-center">
×
<p>{{ Session::get('success') }}</p><br>
</div>
#endif
<br>
<form role="form" action="{{ route('stripe.post') }}" method="post" class="require-validation"
data-cc-on-file="false" data-stripe-publishable-key="{{ env('STRIPE_KEY') }}"
id="payment-form">
#csrf
<div class='form-row row'>
<div class='col-xs-12 col-md-6 form-group required'>
<label class='control-label'>Name on Card</label>
<input class='form-control' size='4' type='text'>
</div>
<div class='col-xs-12 col-md-6 form-group required'>
<label class='control-label'>Card Number</label>
<input autocomplete='off' class='form-control card-number' size='20' type='text'>
</div>
</div>
<div class='form-row row'>
<div class='col-xs-12 col-md-4 form-group cvc required'>
<label class='control-label'>CVC</label>
<input autocomplete='off' class='form-control card-cvc' placeholder='ex. 311'
size='4' type='text'>
</div>
<div class='col-xs-12 col-md-4 form-group expiration required'>
<label class='control-label'>Expiration Month</label>
<input class='form-control card-expiry-month' placeholder='MM' size='2' type='text'>
</div>
<div class='col-xs-12 col-md-4 form-group expiration required'>
<label class='control-label'>Expiration Year</label>
<input class='form-control card-expiry-year' placeholder='YYYY' size='4'
type='text'>
</div>
</div>
{{-- <div class='form-row row'>
<div class='col-md-12 error form-group hide'>
<div class='alert-danger alert'>Please correct the errors and try
again.
</div>
</div>
</div> --}}
<div class="form-row row">
<div class="col-xs-12">
<button class="btn btn-primary btn-lg btn-block" type="submit">Pay Now</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>

Getting error when click in my second post for the single page

When I am trying to open first post in single page, it's opening and when trying to open my second post in single page it;s showing "Trying to get property 'title' of non-object"
Here is code
FrontendController
public function singlePost($slug)
{
$post= Post::where('slug', $slug)->first();
return view('single')->with('post', $post)
->with('title', $post->title)
->with('settings', Setting::first())
->with('categories', Category::take(4)->get());
}
single.blade.php
in that I am using same frontend controller for same page
#extends('layouts.frontend')
#section('content')
<div id="product-post">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="heading-section">
<img src="{{$post->featured}}" alt="" />
</div>
</div>
</div>
<div id="single-blog" class="page-section first-section">
<div class="container">
<div class="row">
<div class="product-item col-md-12">
<div class="row">
<div class="col-md-8">
<div class="product-content">
<div class="product-title">
<h3>{{$post->title}}</h3>
<span class="subtitle">4 comments</span>
</div>
<p>
{!! $post->content!!}
</p>
</div>
<div class="leave-form">
<form action="#" method="post" class="leave-comment">
<div class="row">
<div class="name col-md-4">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="email col-md-4">
<input type="text" name="email" id="email" placeholder="Email" />
</div>
<div class="subject col-md-4">
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
</div>
<div class="row">
<div class="text col-md-12">
<textarea name="text" placeholder="Comment"></textarea>
</div>
</div>
<div class="send">
<button type="submit">Send</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
You have to check whether the value is coming from table or not before getting exact column value. In that case if your table return empty result you can redirect it to 404 page.
Please refer the code below :
public function singlePost($slug)
{
$post= Post::where('slug', $slug)->first();
if($post) {
return view('single')->with('post', $post)
->with('title', $post->title)
->with('settings', Setting::first())
->with('categories', Category::take(4)->get());
} else {
// You can redirect to 404 page
}
}

Get dealership under a company

I have branch index page it contains 2 drop-down menu called company and dealership when i click on company it contains a company i created when click on a company the corresponding dealership should list in the dealership dropdown. i used eloqent straightly into index page i did that because the i can't access the company and dealership in the index page
Index
#include('theme.header')
<?php use Illuminate\Support\Facades\DB;?>
<div class="page-content-wrapper ">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
</div>
<h4 class="page-title">Branch Management</h4>
</div>
</div>
</div>
<!-- end page title end breadcrumb -->
<div class="row">
<div class="col-12">
<div class="card m-b-30">
<div class="card-body">
<h4 class="mt-0 header-title">Branch</h4>
<br>
<br>
<form id="form" method="post" action="{{route('branch.store')}}">
{{csrf_field()}}
<div class="form-group row">
<label class="col-sm-2 col-form-label">Company</label>
<div class="col-sm-10">
<select class="form-control" id="company" name="company">
<option>Select Company</option>
#foreach(\App\Company::all()->where('status','0') as $company)
<option value="{{$company->comp_id}}">{{$company->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Dealership</label>
<div class="col-sm-10">
<select class="form-control" id="dealer" name=" dealer">
<option>Select Dealership</option>
#foreach(\App\Dealership::join('companies','comp_id','=','dealerships.comp_id')->where('status','0') as $dealership)
<option value="{{$dealership->dlr_id}}">{{$dealership->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input class="form-control" type="email" id="email" name="email" required>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Branch Name</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="branch" name="branch" required>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
<button class="btn btn-primary" id="btn_save" data-toggle="modal"
data-target="#create" type="submit">Save
</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
#include('theme.footer')
First thing first. You need to change queries.
Company::where(‘status’, 0)->get();
And next you missed the tailing get() in the next dropdown.
And why are you not using relationships to query?
Like Muhammad Naumann already said you have to use the get() method to get the actual data:
Company::where(‘status’, 0)->get();
On the company select field you could add an event listener like onChange. In this listener you run a ajax get request to fetch the dealerships for the selected company.
I figured it out with Ajax.
Create a custom function in controller file. In this case Branch controller, this function contains query builder to retrieve the data
Write Ajax, in the index file, the dealership dropdown is hidden default when you select the company the dropdown will show corresponding data.
Index File
#include('theme.header')
<?php use Illuminate\Support\Facades\DB;?>
<script language="javascript">
/*--- Fliter dealership corressponging company---*/
$(document).ready(function () {
$('#dealership_div').hide();
$('#company').change(function () {
alert('hello');
$('#dealership_div').show();
let id = this.value;
$.ajax({
url: '/filter_dealer',
type: "post",
data: {option: id},
success: function (data) {
$('#dealer')
.find('option')
.remove()
.end()
.append(" <option value=''>--- Select dealership ---</option>")
$.each(data, function (key, value) {
$('#dealer')
.append($("<option></option>")
.attr('value', value['dlr_id'])
.text(value['name'])
);
});
},
error: function () {
alert("Error occurred While Processing");
}
});
});
});
</script>
<div class="page-content-wrapper ">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
</div>
<h4 class="page-title">Branch Management</h4>
</div>
</div>
</div>
<!-- end page title end breadcrumb -->
<div class="row">
<div class="col-12">
<div class="card m-b-30">
<div class="card-body">
<h4 class="mt-0 header-title">Branch</h4>
<br>
<br>
<form id="form" method="post" action="{{route('branch.store')}}">
{{csrf_field()}}
<div class="form-group row">
<label class="col-sm-2 col-form-label">Company</label>
<div class="col-sm-10">
<select class="form-control" id="company" name="company">
<option>Select Company</option>
#foreach(\App\Company::all()->where('status','0') as $company)
<option value="{{$company->comp_id}}">{{$company->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group row" id="dealership_div">
<label class="col-sm-2 col-form-label">Dealership</label>
<div class="col-sm-10">
<select class="form-control" id="dealer" name=" dealer">
<option></option>
</select>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input class="form-control" type="email" id="email" name="email" required>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Branch Name</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="branch" name="branch" required>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
<button class="btn btn-primary" id="btn_save" data-toggle="modal"
data-target="#create" type="submit">Save
</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
Branch Controller File With a custom function
public function filter_dealer(Request $request)
{
$company_id=$request->input('option');
$dealership=DB::table('dealerships')->select('dlr_id','name')->where([['comp_id','=',$company_id],['status','=','0']])->get();
return response()->json($dealership);
}
Route File
Route::post('filter_dealer', 'BranchController#filter_dealer')->name('filter_dealer');
If you want to dynamically change the contents of dealership dropdown, on the event of changing the company dropdown, you should use javascript, jquery or similar javascript framework, because PHP is a server side scripting language and require page refresh to change the contents of a web page.

Uploading files in Laravel 5

I'm trying to upload a file with Laravel but it does not work
I will send the field with the meta name view
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane fade in active" id="tab1success">
<form method="post" name="type" action="songs">
{{ csrf_field() }}
<div class="form-group">
<div class="row">
<label class="col-md-3 control-label" for="Name">نام موزیک</label>
<div class="col-md-7">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-music">
</i>
</div>
<input id="Name" name="title" type="text"
placeholder="نام موزیک" class="form-control input-md">
</div>
</div>
</div>
<br>
<div class="row">
<label class="col-md-3 control-label" for="Name (Full name)">دسته
بندی</label>
<div class="col-md-7">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-list">
</i>
</div>
<select id="Name" name="category" type="دسته بندی"
placeholder="دسته بندی" class="form-control input-md">
<option>fun</option>
<option>love</option>
<option>birth</option>
<option>wedding</option>
</select>
</div>
</div>
</div>
<br>
<div class="row">
<label class="col-md-3 control-label" for="Name (Full name)">توضیحات</label>
<div class="col-md-7">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-file-text-o">
</i>
</div>
<textarea id="Name" name="text" placeholder="توضیحات"
class="form-control input-md"></textarea>
</div>
</div>
</div>
<br>
<div class="row">
<label class="col-md-3 control-label" for="Name (Full name)">انتخاب
فایل</label>
<div class="col-md-7">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-folder-o">
</i>
</div>
<input id="meta" name="meta" type="file" placeholder="انتخاب فایل"
class="form-control input-md">
</div>
</div>
</div>
<br>
<div class="row" style="text-align: center">
<div class="col-md-10 " style="text-align: center">
<button id="Name" name="submit" type="submit" placeholder="انتخاب فایل"
class="form-control input-md" style="text-align: center">اضافه
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
Controller
public function create(Request $req, $type) {
$this->authorize('is_admin');
$req->file('meta')->store('app');
// $path = Storage::putFile('app', $req->file('meta'))
}
error
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function store() on null
Here is an image of the error
Does anybody know what i should do about this?
Add enctype="multipart/form-data" to your <form> tag in your blade:
<form method="post" name="type" action="songs" enctype="multipart/form-data">
Based on your blade file you can see that the file meta being uploaded is not required, so in your controller, you need to check if the file was sent before calling the store method on it. Check this:
public function create(Request $req, $type) {
$this->authorize('is_admin');
$file = $req->file('meta') ? $req->file('meta')->store('app') : null;
}

Resources