Must provide source or customer. laravel 8 stripe payment gateway - laravel

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>

Related

How to insert a selected dropdownlist text into database in laravel

I want to insert buyer name from dropdown list into database. how can I select my dropdown selected text and save it into database table. I have a dropdown field and some text field to insert data into my database table.
Here is my controller:
function GetBuyerList(){
$buyerList=BuyerModel::all();//get data from table
// $buyerList=BuyerModel::lists('buyer_name','id');
//return $buyer_name;
return view('order',compact('buyerList'));//send data to view
}
function CreateOrder(Request $request){
$user_id= $request->input('user_id');
$buyer_name= $request->input('buyer_name');
$style_name= $request->input('style_name');
$season= $request->input('season');
$brand_name= $request->input('brand_name');
$garmments_type= $request->input('garmments_type');
$order_quantity= $request->input('order_quantity');
$fob= $request->input('fob');
$total_fob= $request->input('total_fob');
$merchandiser_name= $request->input('merchandiser_name');
$order_no= $request->input('order_no');
$order_date= $request->input('order_date');
$status= $request->input('status');
$input_date= $request->input('input_date');
$note= $request->input('note');
$result=OrderModel::insert([
'user_id'=>$user_id,
'buyer_name'=>$buyer_name,
'style_name'=>$style_name,
'season'=>$season,
'brand_name'=>$brand_name,
'garmments_type'=>$garmments_type,
'order_quantity'=>$order_quantity,
'fob'=>$fob,
'total_fob'=>$total_fob,
'merchandiser_name'=>$merchandiser_name,
'order_no'=>$order_no,
'order_date'=>$order_date,
'status'=>$status,
'input_date'=>$input_date,
'note'=>$note,
]);
return view('order');
}
Here is my blade code
#extends('Layout.app')
#section('content')
<br><br><br><br>
<div class="orderDiv container col-8">
<div class="d-flex justify-content-center align-items-center my-10 ">
<div class="card full-width">
<div class="card-header">
<h3>Orders</h3>
</div>
<div class="card-body">
<form>
<div class="row">
<div class="col-md-2">
<label for="category" class=" control-label">Buyer Name</label>
</div>
<div class="col-md-4">
<select class="buyerselect form-control full-width" id="buyerSelectId" name="buyer" required="">
<option value="0" disabled="true" selected="true">-Select Buyer-</option>
#foreach($buyerList as $buyer)
<option value="{{$buyer->id}}">{{$buyer->buyer_name}}</option>
#endforeach
{{-- <option selected value="">Select Buyer</option>--}}
{{-- <option value='564'>564</option>--}}
</select>
{{-- {!! Form::select('id',$buyerList,null,['class'=>'form-control']) !!}--}}
</div>
<div class="col-md-4">
<button id="buyerModalBtnId" type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#addBuyerModal"><i class="fas fa-plus"></i>
Add New Buyer
</button>
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Style#</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Season</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Brand</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-md-2">
<label for="category" class=" control-label">Garments Type</label>
</div>
<div class="col-md-4">
<select class="form-control select2" name="garmentstype" style="width: 75%;" required="">
<option selected value="">Select Garments</option>
<option value='Baby Jacket'>Baby Jacket</option>
</select>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#exampleModal2"><i class="fas fa-plus"></i>
Add Germants Type
</button>
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Company Name</label>
</div>
<div class="col-md-4">
<select class="form-control full-width" name="buyer" required="">
<option selected value="">Select Company</option>
<option value='564'>Friend's Knittings</option>
<option value='Benetton'>Debonair Ltd</option>
<option value='HM'>Orbitex Knitting</option>
<option value='CA'>DPQSL</option>
</select>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Order Qty</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">FOB</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Concern Merchandiser</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-2">
<div class="col-md-2">
<label for="category" class=" control-label">orderDate</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">OrderNo</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-12">
<center>
<button type="submit" class="btn btn-success">Submit</button>
</center>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- modal 1 -->
<div class="modal fade" id="addBuyerModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Buyer</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<form>
<div class="modal-body">
<div id="addBuyerInformationId" class="form-group">
<label for="tstock" class="col-sm-2 control-label">Buyer Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="addBuyerNameId" name="garmentstype" placeholder="Input Buyer Name">
</div><br>
<label for="tstock" class="col-sm-2 control-label">Buyer Country</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="addBuyerCountryId" name="garmentstype" placeholder="Input Buyer Country">
</div>
<br>
</div><br>
<br>
<label for="tstock" class="col-sm-2 control-label">User Id</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="addBuyerUserId" name="garmentstype" placeholder="Input User Id">
</div>
<br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">
Close
</button>
<button id="buyerAddConfirmButton" type="button" class="btn btn-primary" >Save changes</button>
</div>
<!-- modal2 -->
<div class="modal fade" id="exampleModal2" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Create Garments Type</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<form>
<div class="modal-body">
<div class="form-group">
<label for="tstock" class="col-sm-2 control-label">Select</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="garmentstype" name="garmentstype" placeholder="Garments Type">
</div>
<br>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
<!-- End your project here-->
#endsection
I already insert data into buyer table
My custom.js file
$(document).ready(function () {
$('#VisitorDt').DataTable();
$('.dataTables_length').addClass('bs-select');
});
$('#buyerModalBtnId').click(function() {
$('#addBuyerModal').modal('show');
});
$('#buyerAddConfirmButton').click(function() {
// var id=$(this).data('id');
var name = $('#addBuyerNameId').val();
var country = $('#addBuyerCountryId').val();
var user=$('#addBuyerUserId').val();
BuyerAdd(name, country,user);
});
function BuyerAdd(buyerName, buyerCountry,buyerUserId) {
if (buyerName.length == 0) {
toastr.error('Buyer Name is Empty !');
} else if (buyerCountry.length == 0) {
toastr.error('Buyer Description is Empty !');
}
else if (buyerUserId.length == 0) {
toastr.error('Buyer User Id is Empty !');
}
else {
$('#buyerAddConfirmButton').html("<div class='spinner-border spinner-border-sm' role='status'></div>"); ///Animation Set
axios.post('/BuyerAdd', {
name: buyerName,
country: buyerCountry,
user_id:buyerUserId,
})
.then(function(response) {
$('#buyerAddConfirmButton').html("Add");
if (response.status == 200) {
if (response.data == 1) {
// alert('Success');
$('#addBuyerModal').modal('hide');
toastr.success('Add Successfull');
$('#buyerAddConfirmButton').addClass('data-mdb-dismiss');
//getServicesData();
} else {
// alert('Failed');
$('#addBuyerModal').modal('hide');
toastr.error('Add Failed !!');
//getServicesData();
}
} else {
$('#addBuyerModal').modal('hide');
toastr.error('Something Went Wrong');
}
})
.catch(function(error) {
$('#addBuyerModal').modal('hide');
toastr.error('Something Went Wrong');
});
}
}
// Order Data Part
Regardless of some formatting errors and codestyle, here is the short workflow for your question:
validate requested data
instead of insert, use OderModel::create($request->input())
make the fields in your Order Model fillable
if you still need to edit the request data, create a new array and then give it to the create method with (OrderModel::create($newModifiedRequestedData);)
Frontend/view is clear?
The request name which you are using in controller for buyer as buyer_name it should be same as select tag in name with buyer_name.
Replace you blade file with below code and check*
#extends('Layout.app')
#section('content')
<br><br><br><br>
<div class="orderDiv container col-8">
<div class="d-flex justify-content-center align-items-center my-10 ">
<div class="card full-width">
<div class="card-header">
<h3>Orders</h3>
</div>
<div class="card-body">
<form>
<div class="row">
<div class="col-md-2">
<label for="category" class=" control-label">Buyer Name</label>
</div>
<div class="col-md-4">
<select class="buyerselect form-control full-width" id="buyerSelectId" name="buyer_name" required="">
<option value="0" disabled="true" selected="true">-Select Buyer-</option>
#foreach($buyerList as $buyer)
<option value="{{$buyer->id}}">{{$buyer->buyer_name}}</option>
#endforeach
{{-- <option selected value="">Select Buyer</option>--}}
{{-- <option value='564'>564</option>--}}
</select>
{{-- {!! Form::select('id',$buyerList,null,['class'=>'form-control']) !!}--}}
</div>
<div class="col-md-4">
<button id="buyerModalBtnId" type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#addBuyerModal"><i class="fas fa-plus"></i>
Add New Buyer
</button>
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Style#</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Season</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Brand</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-md-2">
<label for="category" class=" control-label">Garments Type</label>
</div>
<div class="col-md-4">
<select class="form-control select2" name="garmentstype" style="width: 75%;" required="">
<option selected value="">Select Garments</option>
<option value='Baby Jacket'>Baby Jacket</option>
</select>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#exampleModal2"><i class="fas fa-plus"></i>
Add Germants Type
</button>
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Company Name</label>
</div>
<div class="col-md-4">
<select class="form-control full-width" name="buyer" required="">
<option selected value="">Select Company</option>
<option value='564'>Friend's Knittings</option>
<option value='Benetton'>Debonair Ltd</option>
<option value='HM'>Orbitex Knitting</option>
<option value='CA'>DPQSL</option>
</select>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Order Qty</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">FOB</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Concern Merchandiser</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-2">
<div class="col-md-2">
<label for="category" class=" control-label">orderDate</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">OrderNo</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-12">
<center>
<button type="submit" class="btn btn-success">Submit</button>
</center>
</div>
</div>
</div>
</form>

how to validate Unique database field on Controller in laravel

Good Day, I am new in Laravel environment. I am developing a simple school enrollment registration website but having trouble in validation on my controller..
My plan is, when the user will register in the website, username textbox should be validated if the username is already used by other student. i tried every possible tutorial i found in the net but i have no luck...
Here is my page, red circle should be validated if the input username already exist in the database..
Whole code in .blade
<!--Registration start here -->
<form method="Post" action="{{url('store_account_Registration')}}">
#csrf
#if(Session::get('success'))
<div class="alert alert-danger">
{{ Session::get('success')}}
</div>
#endif
#if(Session::get('fail'))
<div class="alert alert-danger">
{{ Session::get('fail')}}
</div>
#endif
<div class="col-sm-12 form-group">
<input type="hidden" class="form-control" name="uniqID3" id="uid" placeholder="Enrollment Registration Number" value="{{ $regid3 }}" >
</div>
<div class="col-sm-12 form-group">
<input type="hidden" class="form-control" name="pfulname3" id="name-f" placeholder="Enrollment Registration Number" required value="{{ $fulname4 }}" >
</div>
<div class="container-fluid" style="margin-bottom: 2em">
<div class="row justify-content-center align-items-center" style="padding: 10px">
<div class="card col-md-5" style="transform: none;>
<div class="card-body">
<div class="alert alert-primary" role="alert" style="margin-top: 1em">
<p>Name: <strong>{{ $fulname4 }}</strong></p>
<p>Enrollment No.: <strong>{{ $regid3 }}</strong></p>
</div>
<input type="hidden" class="hide" id="csrf_token" name="csrf_token" value="C8nPqbqTxzcML7Hw0jLRu41ry5b9a10a0e2bc2">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Username</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-user" aria-hidden="true"></i></span>
</div>
<input type="text" class="form-control" name="username" id="username" placeholder="Username" required value="{{ old('username')}}" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('username'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Password</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-lock" aria-hidden="true"></i></span>
</div>
<input type="password" id="password" name="password" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Must have at least 6 characters' : ''); if(this.checkValidity()) form.password_two.pattern = this.value;" class="form-control" title="Password is needed" required placeholder="Password" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('password'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Confirm Password</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-lock" aria-hidden="true"></i></span>
</div>
<input id="password_two" type="password" name="password_two" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Please enter the same Password as above' : '');" placeholder="Confirm Password" class="form-control" title="Confirm Password is needed" required placeholder="Confirm Password" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('password_two'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row" style="margin-top: 1em" >
<div class="col-md-12" style="margin-bottom: 2em">
<input type="hidden" name="redirect" value="">
<!-- <button type="submit" class="btn btn-primary btn-lg btn-block" name="submit">Save OASIS Account</button> -->
<!-- < <p class="btn btn-primary btn-lg btn-block">Save OASIS Account</p> -->
<button type="submit" class="btn btn-primary btn-lg btn-block">Save OASIS Account</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Registration start here -->
</div>
</form>
enter code here
I always got this error..
Here is my code..
my validation in my controller
public function store_account_Registration(Request $request)
{
request()->validate([
'username' => 'required|min:6|unique:TempAccount,AccountName,'
]);
// $this->validator($request->all())->validate();
$current_date = date('Y-m-d H:i:s');
$query = DB::table('TempAccount')->insert([
'RegID'=>$request->input('uniqID3'),
'FullName'=>$request->input('pfulname3'),
'AccountName'=>$request->input('username'),
'Pass'=>$request->input('password'),
'created_at'=> $current_date,
'updated_at'=> $current_date,
]);
if($query){
return back()->with('success', 'Data has been Successfyll inserted');
// return view('pages.enrollment_success');
// return redirect()->route('pages.enrollment_GradeLevelSchoolInfo', ['uniqIDd' => 1]);
// return redirect('enrollment_GradeLevelSchoolInfo');
}
else
{
return back()->with('fail', 'something went wrong');
}
}
my Route in web.php
Route::get('pages',[accountregistration::class, 'index']);
Route::Post('store_account_Registration', [accountregistration::class, 'store_account_Registration']);
my action in form..
The issue is in your form. You are not reaching the correct route at all.
Also you are missing the #csrf token or at least not shown in your print screen
<form action="{{url('store_account_Registration')}}" method="POST">
#csrf
In your validation you can remove the trailing coma after AccountName as well.

Showing Not Acceptable 406 error in laravel

I am getting a new error and its first time I am facing such error. Whenever I submit form and if it contains '%' in any field, then it shows me the 406 Not Acceptable error.
Also, when I submit the form and any field didn't contain '%' then form is successfully submitted.
I have already tried adding
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
in database.php but it didn't work.
Also, I have found in R&D that by adding 'mysql_real_escape_string' in PHP,, this can be resolved. But ho it can be used in laravel..
Please help me out,
Thanks in advance.
<div id="page-wrapper">
<div id="page-inner">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
#include('admin.partials.flash_message')
<form action="{{ $action }}" method="post" enctype="multipart/form-data">
#csrf()
<?php /*#if(!empty($method)) #method($method) #endif*/ ?>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label>RFP Title <span class="text-danger">*</span> :</label>
</div>
<div class="col-md-9">
<input type="text" class="form-control" name="rfp_title" value="{{ $pageTitle }}" {{ $prop }} maxlength="100">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label>RFP Description <span class="text-danger">*</span> :</label>
</div>
<div class="col-md-9">
<textarea id="summernote" name="rfp_description"></textarea>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label>Organisation <span class="text-danger">*</span> :</label>
</div>
<div class="col-md-9">
<input type="text" class="form-control" name="organisation" value="{{ $pageTitle }}" {{ $prop }} maxlength="100">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label>Publish Date <span class="text-danger">*</span> :</label>
</div>
<div class="col-md-9">
<input type="text" class="form-control" name="publish_date" value="{{ $pageTitle }}" {{ $prop }} maxlength="100" readonly>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label>Closing Date <span class="text-danger">*</span> :</label>
</div>
<div class="col-md-9">
<input type="text" class="form-control" name="closing_date" value="{{ $pageTitle }}" {{ $prop }} maxlength="100" readonly>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label>Company Image <span class="text-danger">*</span> :</label>
</div>
<div class="col-md-9">
<input type="file" name="company_image" id="imageUpload" accept=".png,.jpg,.jpeg" class="hide">
<label for="imageUpload" class="upload-poster mr-5">Select file</label> Max Size 2 MB<br>
<img src="{{ asset('public/assets/admin/images/dummy-logo.jpg')}}" id="imagePreview" class="organisation-logo" alt="Your image will appear here.">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label>Attachment <span class="text-danger">*</span> :</label>
</div>
<div class="col-md-9">
<input type="file" name="attachment" id="file-2" class="inputfile" data-multiple-caption="{count} files selected" accept=".pdf,.doc,.docx" multiple>
<label for="file-2" class="mr-5"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg> <span>Select File</span></label> Max Size 2 MB
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label>Contact Person :</label>
</div>
<div class="col-md-9">
<input type="text" class="form-control" name="contact_person" value="{{ $pageTitle }}" {{ $prop }} maxlength="100">
</div>
</div>
</div>
<div class="form-group" style="margin-top: 20px;">
<input type="submit" class="btn btn-primary" value="Submit" name="btn_btn_add_product" {{ $prop }}>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>

Laravel not returning error messages when there is more then 12 validation rules

ok this is messed up... there is a simple form with 20 inputs. I'm submitting this form with no values. and my custom validation rules are all "required" . so i want it to show me errors . but the thing is . out of 20 rules any 12 rules work (in random) . as soon as I add 13th rule it stops returning error messages.
//// this is the form ////
<form method="POST" action="{{route('addschoolbranchindb')}}">
#csrf
<div class="col-xl-12 order-xl-1 mt-5">
<div class="card bg-secondary shadow">
<div class="card-header bg-white border-0">
<div class="row align-items-center">
<div class="col-8">
<h3 class="mb-0">Add School Branch</h3>
</div>
<div class="col-4 text-right">
<input type="submit" value="submit" name="submit" class="btn btn-sm btn-primary">
</div>
</div>
</div>
<div class="card-body">
{{ count($errors)}}
<h6 class="heading-small text-muted mb-4">School information</h6>
<div class="row mt-4">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold; width:100%" class="" for="fk_school_id">Select School</label>
</div>
<div class="col-md-8">
<select class="form-control form-control-alternative fk_school_id" id="fk_school_id" name="fk_school_id">
<option value=""></option>
#foreach ($schools as $school)
<option value="{{$school->school_id}}">{{$school->school_name}}</option>
#endforeach
</select>
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('fk_school_id')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="sc_br_name">Branch Name</label>
</div>
<div class="col-md-8">
<input type="text" id="sc_br_name" name="sc_br_name" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Branch Name">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('sc_br_name')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="sc_br_address">School Address</label>
</div>
<div class="col-md-8">
<input type="text" id="sc_br_address" name="sc_br_address" class="disable_on_sc_id form-control form-control-alternative"
placeholder="School Address">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('sc_br_address')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="sc_br_status">School status</label>
</div>
<div class="col-md-8">
<select class="disable_on_sc_id form-control form-control-alternative sc_br_status" id="sc_br_status" name="sc_br_status">
<option value="1">Un-Registered</option>
<option value="2">Under Process</option>
<option value="3">Registered</option>
{{-- #foreach ($schools as $school)
<option value="{{$school->school_id}}">{{$school->school_name}}</option>
#endforeach --}}
</select>
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('sc_br_status')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="no_of_boys">No of Boys</label>
</div>
<div class="col-md-8">
<input type="text" id="no_of_boys" name="no_of_boys" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Number of Boys">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('no_of_boys')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="no_of_girls">No of Girls</label>
</div>
<div class="col-md-8">
<input type="text" id="no_of_girls" name="no_of_girls" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Number of girls">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('no_of_girls')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="sc_br_covered_area">Covered Area</label>
</div>
<div class="col-md-8">
<input type="text" id="sc_br_covered_area" name="sc_br_covered_area" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Total Covered Area">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('sc_br_covered_area')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="no_of_teachers">No of Teachers</label>
</div>
<div class="col-md-8">
<input type="text" id="no_of_teachers" name="no_of_teachers" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Number Of Teachers">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('no_of_teachers')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<hr class="my-4" />
<h6 class="heading-small text-muted mb-4">Owner information</h6>
<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="owner_name">Owner Name</label>
</div>
<div class="col-md-8">
<input type="text" id="owner_name" name="owner_name" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Owner Name">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('owner_name')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-5">
<label style="font-weight:bold" class="" for="owner_phone">Owner Phone No</label>
</div>
<div class="col-md-7">
<input type="text" id="owner_phone" name="owner_phone" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Owner Number">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('owner_phone')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<div class="row mt-5">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="owner_email">Owner Email</label>
</div>
<div class="col-md-8">
<input type="text" id="owner_email" name="owner_email" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Owner Email">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('owner_email')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<hr class="my-4" />
<h6 class="heading-small text-muted mb-4">Principal information</h6>
<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="principal_name">Principal Name</label>
</div>
<div class="col-md-8">
<input type="text" id="principal_name" name="principal_name" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Principal Name">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('principal_name')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-5">
<label style="font-weight:bold" class="" for="principal_phone">Principal Phone No</label>
</div>
<div class="col-md-7">
<input type="text" id="principal_phone" name="principal_phone" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Principal Number">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('principal_phone')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<div class="row mt-5">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="principal_email">Principal Email</label>
</div>
<div class="col-md-8">
<input type="text" id="principal_email" name="principal_email" class="disable_on_sc_id form-control form-control-alternative"
placeholder="Principal Email">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('principal_email')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<hr class="my-4" />
<h6 class="heading-small text-muted mb-4">Area information</h6>
<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<label style="font-weight:bold" class="" for="pov_for_subarea">Select Province</label>
</div>
<div class="col-md-8">
<select class="form-control form-control-alternative pov_for_subarea" id="pov_for_subarea" name="pov_for_subarea">
<option value=""></option>
#foreach ($provinces as $province)
<option value="{{$province->province_id}}">{{$province->province_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="col-md-6">
<div class="col-md-5">
<label style="font-weight:bold" class="" for="city_for_subarea">Select City</label>
</div>
<div class="col-md-7">
<select class="form-control form-control-alternative city_for_subarea" id="city_for_subarea" name="city_for_subarea">
<option value=""></option>
</select>
</div>
</div>
</div>
<div class="row mt-5">
<div class="col-md-6">
<div class="col-md-5">
<label style="font-weight:bold" class="" for="areaselect">Select Area</label>
</div>
<div class="col-md-7">
<select class="form-control form-control-alternative areaselect" id="areaselect" name="areaselect">
<option value=""></option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="col-md-5">
<label style="font-weight:bold" class="" for="fk_subarea_id">Select Sub-Area</label>
</div>
<div class="col-md-7">
<select class="form-control form-control-alternative fk_subarea_id" id="fk_subarea_id" name="fk_subarea_id">
</select>
</div>
</div>
</div>
<div class="row mt-5">
<div class="col-md-6">
<div class="col-md-5">
<label style="font-weight:bold" class="" for="latitude">Latitude</label>
</div>
<div class="col-md-7">
<input type="text" id="latitude" name="latitude" class="form-control form-control-alternative"
placeholder="Latitude">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('latitude')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-5">
<label style="font-weight:bold" class="" for="longitude">Longitude</label>
</div>
<div class="col-md-7">
<input type="text" id="longitude" name="longitude" class="form-control form-control-alternative"
placeholder="Longitude">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('longitude')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
<div class="row mt-5">
<div class="col-md-6">
<div class="col-md-5">
<label style="font-weight:bold" class="" for="location_string">Location String</label>
</div>
<div class="col-md-7">
<input type="text" id="location_string" name="location_string" class="form-control form-control-alternative"
placeholder="Location String">
</div>
<div class="row" style="text-align:center">
<div class="col-md-8">
#error('location_string')
<span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
#enderror
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
//// this is the controller ////
public function addSchoolBranchInDb(Request $request)
{
// dd($request);
$rules = [
'fk_school_id' => 'required',
'sc_br_name' => 'required',
'sc_br_address' => 'required',
'sc_br_status' => 'required',
'no_of_boys' => 'required',
'no_of_girls' => 'required',
'sc_br_covered_area' => 'required',
'no_of_teachers' => 'required',
'owner_name' => 'required',
'owner_phone' => 'required',
'owner_email' => 'required',
'principal_name' => 'required',
// 'principal_phone' => 'required',
// 'principal_email' => 'required',
// 'fk_subarea_id' => 'required',
// 'latitude' => 'required',
// 'longitude' => 'required',
// 'location_string' => 'required',
];
$messages = [
'fk_school_id.required' => 'School Name is required',
'sc_br_name.required' => 'School Branch Name is required',
'sc_br_address.required' => 'School Address is required',
'sc_br_status.required' => 'School Status is required',
'no_of_boys.required' => 'Number of boys is required',
'no_of_girls.required' => 'Number of girls is required',
'sc_br_covered_area.required' => 'School covered area is required',
'no_of_teachers.required' => 'Number of teachers is required',
'owner_name.required' => 'Owner Name is required',
'owner_phone.required' => 'Owner Phone is required',
'owner_email.required' => 'Owner Email is required',
'principal_name.required' => 'Principal Name is required',
'principal_phone.required' => 'Principal Phone is required',
'principal_email.required' => 'Principal Email is required',
'fk_subarea_id.required' => 'Subarea is required',
'latitude.required' => 'Latitude is required',
'longitude.required' => 'Longitude is required',
'location_string.required' => 'Location String is required',
];
$validator = validator::make($request->all() , $rules );
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
$sc_branch = new Schoolbranch;
$sc_branch->fill($request->all());
$sc_branch->save();
Session::flash('message','School Branch is added');
Session::flash('alert-class', 'alert-success');
return redirect()->back();
}
Ok yes I got the answer from laracast. Alex bouma's answer is right . Just change driver session to file. It works – Tallal just now

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