how to send data from the view to the controller In laravel - laravel

I'm doing a web application, and I get to a point where I can not move forward, I do not know how to do this, I'm starting with laravel so maybe the solution is very simple:
public function detalle($id){
// $nota = App\Nota::find($id);
//Aquí valida si existe sino redirije al 404
$producto = App\Producto::findOrFail($id);
$cantidad = 1;
return view('productos.detalle', compact('producto','cantidad'));
}
View:
<div class="card col-6 ">
<div class="card-body card-buy">
<h1 class="display-4 ">{{$producto->nombre}}</h1>
<p class="h3 mt-5">S/ {{$producto->precio}}</p>
<div class="form-inline">
<i class="fas fa-credit-card h1 mr-1"></i>
<p class="mt-2 "> <b>Metodo de pago:</b> A convenir</p>
</div>
<div class="form-inline">
<i class="fab fa-mailchimp ml-2 mr-2 h1"></i>
<p class="mt-2 "> <b>Envio:</b> Disponible a todo el pais</p>
</div>
<div class="form-inline ">
<div class="mt-n5 mr-2">
<b>Cantidad:</b>
</div>
<div class="def-number-input number-input safari_only">
<button onclick="this.parentNode.querySelector('input[type=number]').stepDown()" class="minus"></button>
<input readonly="readonly" class="quantity" min="1" max="{{$producto->stock}}" name="quantity" value="{{$cantidad}}" type="number">
<button onclick="this.parentNode.querySelector('input[type=number]').stepUp()" class="plus"></button>
</div>
<div class="mt-n5 ml-2">
<b class="text-decoration-none"> ( {{$producto->stock}} disponibles)</b>
</div>
</div>
Comprar
</div>
</div>
https://gyazo.com/febcd4c38cb3ef244e7424a3d92079a4
I already created the detail view of my product, and I put a button for the user to select the amount of products he wants, until there is everything right ...
But I want that number that the person chose to go to the next view, which is to confirm
https://gyazo.com/f56cf578808e75a0fab25eeffa8d2c5d
but that data {{$cantidad}} I do not know how to pass it to this new view I put the code:
Controller:
public function detallescompra($id){
$producto = App\Producto::findOrFail($id);
$total = 0;
$num1 = $producto->precio;
$num2 = $producto->stock;
$total = $num1 * $num2;
return view('productos.compra', compact('producto','total'));
}
and in the view:
<div class="container">
<div class="row" id="contenido">
<div class="col-md-8">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<span>Revisa y Confirma</span>
Seguir viendo...
</div>
<div class="card-body">
#if ( session('mensaje') )
<div class="alert alert-success">{{ session('mensaje') }}</div>
#endif
<form method="POST" action="{{ route ('productos.comprafinal') }}">
#csrf
<label class="text-gray">Contacto y Envio:</label>
<div id="contenido">
<input type="name" name="usuario" placeholder="Nombre y Apellido" class="form-control mb-2" required />
<input type="email" name="email" placeholder="Email de contacto" class="form-control mb-2" required />
<input type="number" name="tlf" placeholder="Numero de telefono" class="form-control mb-2" />
<input type="street-address" name="direccion" placeholder="Direccion (Calle - #Casa - Referencia)" class="form-control mb-2" validate required />
<input type="text" name="id" placeholder="" class="form-control mb-2 d-none" value="{{$producto->id}}" />
<input type="text" name="timestamps" placeholder="" class="form-control mb-2 d-none" value="{{$producto->timestamp}}" />
<label class="text-gray">Producto:</label>
<input type="text" name="nombre" placeholder="Precio del Producto" class="form-control mb-2" value="{{$producto->nombre}}" readonly="readonly" />
<input type="text" name="precio" placeholder="Precio del Producto" class="form-control mb-2" value="Precio por unidad: S/ {{$producto->precio}}" readonly="readonly" id="valor1" />
<input type="text" name="cantidad" placeholder="Precio del Producto" class="form-control mb-2" value="Numero de productos: " readonly="readonly" id="valor2" />
<input type="text" name="" placeholder="Precio del Producto" class="form-control mb-2" value="Total a pagar: S/ {{$total}}" readonly="readonly" id="total" />
<button class="btn btn-success btn-block" type="submit">Comprar</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-mod-4">
<div class="card" style="width: 18rem;">
<img src="{{$producto->img}}" class="card-img-top" alt="...">
</div>
</div>
</div>
I just need to spend that {{$cantidad}} in my view productos.compra, So far I have tried many things but nothing has given me even the minimum result
I'm new to this, I need help :(

GG :D
public function detallescompra(Request $request,$id){
$producto = App\Producto::findOrFail($id);
$cantidad = $request->input('cantidad');
$total = 0;
$num1 = $producto->precio;
$num2 = $cantidad;
$total = $num1 * $num2;
return view('productos.compra', compact('producto','total','cantidad'));
}
View:
<form action="{{ route('productos.compra-confirm', $producto) }}" method="POST">
#csrf
<div class="form-inline ">
<div class="mt-n5 mr-2">
<b>Cantidad:</b>
</div>
<div class="def-number-input number-input safari_only">
<button type="button" onclick="this.parentNode.querySelector('input[type=number]').stepDown()" class="minus"></button>
<input readonly="readonly" class="quantity" min="1" max="{{$producto->stock}}" name="cantidad" value="{{$cantidad}}" type="number">
<button type="button" onclick="this.parentNode.querySelector('input[type=number]').stepUp()" class="plus"></button>
</div>
<div class="mt-n5 ml-2">
<b class="text-decoration-none"> ( {{$producto->stock}} disponibles)</b>
</div>
</div>
<button type="submit" class=" align-bottom btn btn-success btn-lg btn-block ">Comprar</button>
</div>
</div>
</form>
routes web:
Route::post('/comprar/{id}', 'HomeController#detallescompra')->name('productos.compra-confirm');

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.

How to ' pass concatenated parameters as single parameter and populate the view page'?

I have tried and got help from stack overflow kind team member and reached till this level, yet I have to go step closer to solve it .However, when
I am trying to pass parameter that is concatenated, example I pass parameter like l/59. Once this parameter is passed, it should retrieve relevant data from table named st_dak_details , and I want data retrieved from that table to populate it in another view page . But it is not working, meaning not getting populated.
first view page where I pass parameter
<div class="col-sm-7 col-md-6 col-lg-4">
<button type="reset" class="btn btn-default" >Reset <span class="glyphicon glyphicon-refresh"></span></button>
<button type="button" class="btn btn-success" id="getbtn" onclick="loadPagcontente('<?php echo site_url()?>/UsermanagementController/forwardtrack')" >Get Detais <span class="glyphicon glyphicon-ok"></span></button>
<!-- <button type="button" class="btn btn-success" id="getbtn" onclick="loadPagcontente('<?php //echo site_url()?>/UsermanagementController/forwardtrack')">Get Detais <span class="glyphicon glyphicon-ok"></span></button> -->
</div>
Inside Controller
function forwardtrack($param='',$param2='') {
if(sizeof($this->db->get_where('st_forward',array('letter_no' =>$param.'/'.$param2))->result_array())>0 && (!($param.'/'.$param2) )){
$data1['message']= 'notallow';
$this->load->view('track1',$data1);
}else{
$data1['name']=$this->db->get_where('bpas_user_profiles',array('AgencyMainParentID' =>$this->session->userdata('ministryId'),'AgencyParentID'=>$this->session->userdata('parentID'),'AgencyID'=>$this->session->userdata('agencyID')))->result_array();
$data1['userdeatils']=$this->ag->tracks($param.'/'.$param2);
$this->load->view('userManagement/forward2', $data1);
}
/* ag=> agency model */
}
Inside model
public function tracks($letterno="")
{
$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno));
if ($query->num_rows() > 0) {
return $query->row();
} else {
return array();
}
}
Inside final view page
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-envelope-o fa-fw"></i>forward to
</div>
<div class="panel-body">
<form class="form-horizontal" enctype="multipart/form-data" action="#" method="post" id="forwardmessage">
<div class="form-group">
<label for="letter"class="col-xs-12 col-lg-1 col-sm-1 col-md-1">letter_no: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<?php if(!empty($userdeatils)){
foreach($userdeatils as $row) { ?>
<!-- your html code -->
<input name="dakLetterNo" id="dakLetterNo" value="<?php echo $row['dakLetterNo'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- <div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">created: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="copy_to" id="copy_to" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required />
</div> -->
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2 control-label">Attachment: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<input type="file" name="Attachment" id="Attachment">
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Subject: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon" id="subjecterr"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="subject" id="Remark" value="<?php echo $row['Remark'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Place: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="place" id="place" value="<?php echo $row['place'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">from: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="from" id="receieve_add" value="<?php echo $row['receieve_add'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Created: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="created" id="created" value="<?php echo $row['created'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- </div> -->
<!-- <div class="form-group"> -->
<!-- <label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Message: </label> -->
<!-- <div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10"> -->
<!-- <span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span> -->
<!-- <input name="message" id="message" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required /> -->
<!-- </div> -->
<!-- </div> -->
<?php } ?> <!-- //foreach close -->
<?php } ?> <!-- //if close -->
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">Message: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<textarea class="form-control" id="message" name="message"></textarea>
<span id="messageerr" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">
Forward to
</label>
<div class="col-lg-6 col-xs-12 col-sm-6 col-md-6">
<select name="forwardto[]" id="agency" class="form-control">
<option value="">Select</option>
<?php
foreach($name as $row): ?>
<option value="<?php echo $row['cid']?>">
<?php echo $row['FirstName'].$row['MiddleName'].$row['LastName']?>
</option>
<?php endforeach;?>
</select>
<span id="forwarderr" class="text-danger"></span>
</div>
<div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
<button type="button" onclick="addmessageto()" class="btn btn-success">Add More</button>
<button type="button" onclick="removemessageto()" class="btn btn-warning">Remove</button>
</div>
</div>
<span id="addmoreforwardto"></span>
<hr />
<div class="form-group">
<div class="col-xs-12 col-lg-10 col-sm-12 col-md-12">
<button type="button" class="btn btn-info" onclick="forwardmessage('forward')"> <i class="fa fa-send"></i> Forward to</button>
<button type="button" class="btn btn-info" onclick="forwardmessage('complete')"> <i class="fa fa-send"></i> Complete Action</button>
<a href="<?php echo base_url()?>index.php/Settings/view_ods_dashboard/"> <button type="button" class="btn btn-warning">
<i class="fa fa-dashboard" aria-hidden="true" ></i> Dashboad</span>
</button>
</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
I expect concatenated parameter that I passed from first view page to retrieve data from table and populate it into the final view page.
If you have data like l/54 or l/59 with varchar datatype column then below query will work.
public function tracks($letterno="")
{
//$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno));
$this->db->select('*');
$this->db->from('st_dak_details');
$this->db->like('dakLetterNo', $letterno); //'%l/54%'
$query= $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return array();
}
}

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;
}

how to select and show data comment by id post in codeigniter

master peace of codeigniter. im new user for this framework.
i have problem to show comment data by id_diskusi in the single post of diskusi. i try to show data using 'where' in the lybrary code but its still not show the data. i hope the people at there can help me & solved this problem.
i use library to get data from database
public function setuju(){
$data=$this->CI->db->query("SELECT komentar.id AS id,
komentar.diskusi_id AS id_diskusi,
komentar.pilih AS pilih,
komentar.nama AS nama,
komentar.email AS email,
komentar.pesan AS pesan,
komentar.tanggal AS tanggal,
diskusi.diskusi_id as nomor_diskusi
FROM diskusi, komentar
WHERE diskusi.diskusi_status='publish' AND komentar.pilih='1' AND komentar.diskusi_id=diskusi.diskusi_id ORDER BY komentar.id DESC
");
return $data->result_array();
}
i use this code to filter data who data on komentar will be show by id of diskusi.
komentar.diskusi_id=diskusi.diskusi_id
but still not work
and its my controller
$data['setuju']=$this->diskusi->setuju();
code in the view
<div id="netral" class="tab-pane">
<?php
foreach ($netral AS $value) {
echo "<div class='box box-body no-border'>
<div class='row'>
<div class='col-md-2'>
<div class='box-profile'>"; ?>
<img alt='user image' style='margin-top:10px' class='profile-user-img img-responsive img-circle' src='<?php echo img_user_url('user.png'); ?>'>
<?php echo"
<h3><center>$value[nama]</center</h3>
</div>
</div>
<div class='col-md-10'>
<div class='callout callout-danger lead'><span class='pull-right'>".format_tanggal($value['tanggal'])."</span><br>
<p>$value[pesan]</p>
</div>
</div>
</div>
</div>";
}?>
</div><!-- /.tab-pane -->
<div class="box box-danger">
<div class="box-header with-border">
<div class="user-block">
<h3 class="no-margin">Tinggalkan Komentar</h3>
</div><!-- /.user-block -->
<div class="box-tools">
<button data-widget="collapse" class="btn btn-danger btn-sm"><i class="fa fa-minus"></i></button>
</div><!-- /.box-tools -->
</div>
<div class="box-body">
<form method='POST' id='komentar' action='<?php echo baseURL('form_visitors/komentar'); ?>' autocomplete='off' method="post" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="inputName">Name</label>
<div class="col-sm-10">
<input type="hidden" name="diskusi_id" value="<?php echo "$diskusi[id]";?>">
<input type="text" placeholder="Nama" data-original-title="Masukkan Nama" required='required' name="nama" id="inputName" class="form-control">
<input type='hidden' class='form-control' name='url' value='<?php echo current_url() ?>' />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputEmail">Email</label>
<div class="col-sm-10">
<input type="email" name="email" data-original-title="Masukkan Email" placeholder="Email" required='required' id="inputEmail" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-10">
<div class="checkbox">
<label>
<input type="radio" name="pilih" value="1"> <i class="fa fa-thumbs-o-up margin-r-5 text-green"> <b>Setuju</b></i>
</label>
<label>
<input type="radio" name="pilih" value="2"> <i class="fa fa-square margin-r-5 text-yellow"> <b>Netral</b></i>
</label>
<label>
<input type="radio" name="pilih" value="3"> <i class="fa fa-thumbs-o-down margin-r-5 text-red"> <b>Tidak Setuju</b></i>
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputExperience">Komentar</label>
<div class="col-sm-10">
<textarea placeholder="Komentar" name="pesan" id="inputExperience" required='required' class="form-control"></textarea>
</div>
</div>
<div class='form-group'>
<label class="col-sm-2 control-label" for="inputExperience"></label>
<div class="col-sm-10">
<div id='recaptcha1'></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-danger" type="submit" id="submit">Submit</button>
<div class="cssload" style="display: none; width: 100px">
<div class="cssload-tube-tunnel"></div>
</div>
</div>
</div>
</form>
</div>
</div>
how can i show comment data according with single post of diskusi who have comment. Thank you very much in advance! sorry for my english.
I can see you are fetching the data from two different tables but you have not used 'JOIN'.
you can try the following query string :
public function setuju(){
$data=$this->CI->db->query("SELECT komentar.id AS id,
komentar.diskusi_id AS id_diskusi,
komentar.pilih AS pilih,
komentar.nama AS nama,
komentar.email AS email,
komentar.pesan AS pesan,
komentar.tanggal AS tanggal,
diskusi.diskusi_id as nomor_diskusi
FROM komentar, diskusi
JOIN diskusi
ON diskusi.diskusi_id=komentar.diskusi_id
WHERE diskusi.diskusi_status='publish' AND komentar.pilih='1' ORDER BY komentar.id DESC
");
return $data->result_array();
}

Resources