when i enter question and click on add button i show error base table not found i cant understand what is issue and its solution so if any one know help me...i waste lot of time on it am begninner so difficult to identify error...
web.php
Route::post('/admin/add_new_question','Admin#add_new_question');
AdminController
public function add_new_question(Request $request)
{
$validator=Validator::make($request->all(),['question'=>'required','option1'=>'required','option2'=>'required','option3'=>'required','option4'=>'required','ans'=>'required']);
if($validator->passes())
{
$question = new Oex_exam_question_master();
$question->exam_id=$request->exam_id;
$question->question=$request->question;
$question->ans=$request->ans;
$question->options=json_encode(array('option1'=>$request->option1,'option2'=>$request->option2,'option3'=>$request->option3,'option4'=>$request->option4));
$question->save();
$arr=array('status'=>'true','message'=>'Question Successfully Added','reload'=>url('admin/add_question/'.$request->exam_id));
}
else{
$arr=array('status'=>'false','message'=>$validator->errors()->all());
}
echo json_encode($arr);
}
add_question.blade.php
#extends('layouts.app')
#section('title','Exam Question')
#section('content')
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">Exam Question</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active">Exam Question</li>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<!-- Default box -->
<div class="card">
<div class="card-header">
<div class="card-tools">
<a class="btn btn-info btn-sm" href="javascript:;" data-toggle="modal" data-target="#myModal">Add New</a>
</div>
</div>
<div class="card-body">
<table class="table table-striped table-bordered table-hover datatable">
<thead>
<tr>
<th>#</th>
<th>Question</th>
<th>Ans</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>#</th>
<th>Question</th>
<th>Ans</th>
<th>Status</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.card-body -->
<!-- /.card-footer-->
</div>
<!-- /.card -->
</div>
</div>
</div>
</section>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add New Exam</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form action="{{ url('admin/add_new_question') }} " class="database_operation">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label>Enter Question</label>
{{ csrf_field() }}
<input type="hidden" name="exam_id" value="{{ Request::segment(3) }}">
<input type="text" name="question" required="required" placeholder="Enter Question" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Select Option 1</label>
<input type="text" required="required" name="option1" placeholder="Enter Option 1" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Select Option 2</label>
<input type="text" required="required" name="option2" placeholder="Enter Option 2" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Select Option 3</label>
<input type="text" required="required" name="option3" placeholder="Enter Option 3" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Select Option 4</label>
<input type="text" required="required" name="option4" placeholder="Enter Option 4" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label>Enter Right Ans</label>
<input type="text" required="required" name="ans" placeholder="Enter Right Ans" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<button class="btn btn-primary"> Add</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
Table oex_exam_question_master
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateOexExamQuestionMastersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('oex_exam_question_masters', function (Blueprint $table) {
$table->increments('id');
$table->string('exam_id')->nullable();
$table->string('question')->nullable();
$table->string('ans')->nullable();
$table->string('options')->nullable();
$table->string('status')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('oex_exam_question_masters');
}
}
Error
{
"message": "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'my_pro_online_ex.oex_exam_question_master' doesn't exist (SQL: insert into `oex_exam_question_master` (`exam_id`, `question`, `ans`, `options`, `updated_at`, `created_at`) values (4, Question 2, D, {\"option1\":\"A\",\"option2\":\"B\",\"option3\":\"C\",\"option4\":\"D\"}, 2020-07-21 07:32:03, 2020-07-21 07:32:03))",
"exception": "Illuminate\\Database\\QueryException",
"file": "C:\\xampp\\htdocs\\project\\online_exm_sys\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php",
"line": 664,
"trace": [
{
"file": "C:\\xampp\\htdocs\\project\\online_exm_sys\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php",
"line": 624,
"function": "runQueryCallback",
"class": "Illuminate\\Database\\Connection",
"type": "->"
You need to assign a table name in your model.
class Oex_exam_question_master extends Model
{
protected $table = 'oex_exam_question_masters';
}
Related
I have a problem , saving data to the database from the input form that I made. The code is running well but the form is not saving the data I input from the form to the database. Did I miss something? when I click on the button to save the info to the database, nothing seems to happen(meaning no error).
Here is my jquery:
var percentageSupport = "";
$('#btnSaveFinanicialSupport').on('click', function () {
if (patientId == "") {
alert("kindly Enter Patient Id ")
return false;
}
if ($('#currentSupport').val() == 0) {
alert('Kindly Give Financial Support');
return false;
}
var totalPayableAmount = $('#payableAmount').val();
var currentSupportAmount = $('#currentSupport').val();
if (currentSupportAmount > totalPayableAmount) {
alert('Kindly Enter Correct Support Amount');
return false;
}
//here to start to set data to call save service.
var percantageSupportAmount = Math.round((currentSupportAmount / totalPayableAmount) * 100);
var supportType = $('select.supportType').val();
var token = supportType.split("#");
var supportTypeId = token[0];
var supportType = token[1];
if (supportType == "SELECT") {
alert('kindly Select Support Type');
return false;
}
var comments = $('#comments').val();
var orderIds = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("orderId");
}).get();
var serviceIds = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("serviceId");
}).get();
var serviceCost = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("price");
}).get();
var servicePayableAmount = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("payableAmount");
}).get();
var serviceFinancialSupport = $("#tbody input:checkbox:checked").map(function () {
return $(this).attr("financialSupport");
}).get();
$.ajax({
type: 'post',
data: {
patientId: patientId, supportTypeId: supportTypeId, percantageSupportAmount: percantageSupportAmount,
comments: comments, serviceIds: serviceIds, orderIds: orderIds, servicePayableAmount: servicePayableAmount,
serviceFinancialSupport: serviceFinancialSupport, serviceCost: serviceCost
},
url: '/saveFinancialSupport',
success: function (data) {
alert("Financial Support Given Successfully")
$("#tbodyy").html("");
$("#tbody").html("");
$('#totalAmount').val('');
$('#totalAmount').text('');
$('#paidAmount').val('');
$('#paidAmount').text('');
$('#supportamount').val('');
$('#supportamount').text('');
$('#comments').val('');
$('#comments').text('');
$('#totalamount').val('');
$('#totalamount').text('');
$('#totalpayable').val('');
$('#totalpayable').text('');
}
});
})
Here is my controller:
//save financial support
public function saveFinancialSupport(Request $req){
$output = array();
$orderIds = $req->orderids;
$serviceIds = $req->serviceids;
$servicePayableAmount = $req->servicePayableAmount;
$serviceFinancialSupport = $req->serviceids;
$serviceCost = $req->serviceCost;
$obj = new SessionClass();
$array = array();
for ($i=0; $i < count($orderIds) ; $i++) {
$price = $serviceCost[$i];
$support = ($servicePayableAmount[$i] * $req->percentageSupport)/100;
$array[$i] = array(
"financialSupport" => $support,
"patientId" => $req->patientId,
"orderId" => $orderIds[$i],
"supportTypeId" => $req->supportTypeId,
"price" => $serviceCost[$i],
"sign" => "+",
"percentageSupport" => $req->percentageSupport,
"comments" => $req->comments,
"active" => "Y",
"refFormNo" => "0",
"serviceId" => $serviceids[$i],
"id" => "123",
"locationId" => $obj->getLocationId(),
"orgId" => $obj->getOrgId(),
"sessionId" => $obj->getSessionId(),
"crtdBy" => $obj->getUserId(),
"crtdTerminalId" => "123");
}
$host = new HostClass();
$obj = new SessionClass();
$data = json_encode($array);
$response = Http::post('127.0.0.1:9000/saveFinancialSupport', $array);
return redirect()->back()->with('alert', 'Record Save Successfully');
}
Here is my web route:
Route::post('saveFinancialSupport' , 'SupportController#saveFinancialSupport');
Here is my web route:
#extends('layouts.theme')
#section('content')
<meta name="csrf-token" content="{{ csrf_token() }}">
<div class="container custom-container">
#include('patientPanel.patientPanel')
<form method="post" action="saveFinancialSupport" id="fsform">
#csrf
<div class="card mb-2">
<div class="card-body pb-2">
<div class="row">
<div class="col-lg-1">
<label>From Date</label>
</div>
<div class="col-lg-2">
<input type="Date" name="fromDate" id="fromDate" class="form-control form-control-sm"
placeholder="Client">
</div>
<div class="col-lg-1">
<label>To Date</label>
</div>
<div class="col-lg-2">
<input type="Date" name="toDate" id="toDate" class="form-control form-control-sm">
</div>
<div class="col-lg-1 mt-1" style="font-size: 14px; font-weight:bold;">
<label><input type="checkbox" name="All Date" id="allDates">  All Dates</label>
</div>
<div class="col-lg-1 mt-1">
<label>Support Limit</label>
</div>
<div class="col-lg-1">
<input type="text" name="supportLimit" id="supportLimit" class="form-control form-control-sm"
value="" readonly="">
</div>
<div class="col-lg-1 mt-1">
<label>Support Given</label>
</div>
<div class="col-lg-1">
<input type="text" name="supportgiven" id="supportgiven" class="form-control form-control-sm"
value="" readonly="">
</div>
</div>
</div>
</div>
<!-- //end card one -->
<div class="row">
<div class="col-lg-12">
<div class="block">
<div class="card-body p-0">
<div style="height:200px;overflow-y: auto;" class="outer">
<table id="tblServiceOrders" class="table table-striped table-sm table-hover table-bordered">
<thead class="bg-dark">
<tr class="font" style="color: white;">
<th>Order Date</th>
<th>Order By</th>
<th>Service Name</th>
<th>Cost</th>
<th>Support</th>
<th>Payable</th>
<th>Select</th>
</tr>
</thead>
<tbody id="tbody" class="rowClick">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="collapse" id="tblSupportDetailCollapse">
<div class="block">
<div class="card-body p-0">
<div style="height:100px;overflow-y: auto;" class="outer">
<table id="supportDetail" class="table table-striped table-sm table-hover table-bordered">
<thead class="bg-dark">
<tr class="font" style="color: white;">
<th>Order Date</th>
<th>Order By</th>
<th>Service Name</th>
<th>Cost</th>
<th>Support</th>
<th>Payable</th>
<th>Select</th>
</tr>
</thead>
<tbody id="tbody" class="rowClick">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- end second table -->
<!-- here is start final calculation of financial support -->
<div class="card">
<div class="card-body pb-2">
<div class="row">
<div class="col-lg-1">
<label>Total Amount</label>
</div>
<div class="col-lg-1">
<input type="text" name="totalAmount" id="totalAmount" class="form-control form-control-sm"
value="" readonly="">
</div>
<div class="col-lg-1">
<label>Support </label>
</div>
<div class="col-lg-1">
<input type="text" name="supportAmount" id="supportAmount"
class="form-control form-control-sm" value="" readonly="">
</div>
<div class="col-lg-1">
<label>Payable</label>
</div>
<div class="col-lg-1">
<input type="text" name="payableAmount" id="payableAmount"
class="form-control form-control-sm" value="" readonly="">
</div>
<div class="col-lg-2 mb-1">
<select class="form-control form-control-sm supportType" id="supportType">
<option value="SELECT">SELECT</option>
</select>
</div>
<div class="col-lg-1 mb-1">
<select class="form-control form-control-sm percentageSupport" id="percentageSupport">
<option value="SELECT">SELECT</option>
</select>
</div>
<div class="col-lg-1">
<input type="text" name="currentSupport" id="currentSupport"
class="form-control form-control-sm" value="" >
</div>
<div class="col-lg-1">
<label>Net Payable</label>
</div>
<div class="col-lg-1">
<input type="text" name="netPayable" id="netPayable" class="form-control form-control-sm"
value="" readonly="">
</div>
</div>
</div>
</div>
<!-- here calacualtion here -->
<div class="card mb-2">
<div class="card-body forms">
<div class="row">
<div class="col-lg-1 mb-1">
<label>Remarks</label>
</div>
<div class="col-lg-11 mb-1">
<input type="text" name="comments" id="comments" class="form-control form-control-sm">
</div>
</div> <!-- row end -->
</div> <!-- card body forms -->
</div> <!-- card mb-2 -->
<div class="block border">
<div class="card-body pt-2 pb-2">
<div class="row">
<div class="col-lg-2">
</div>
<div class="col-lg-2">
<a class="btn btn-sm btn-secondary col-lg-12" id="btnSaveFinanicialSupport" style="color:white">Financial Support</a>
</div>
<div class="col-lg-2">
<a class="btn btn-sm btn-outline-danger col-lg-12" id="">Cancel Support</a>
</div>
<div class="col-lg-2">
<a class="btn btn-sm btn-secondary col-lg-12" id="btngenerateinvoice"
style="color:white">Patient Support History</a>
</div>
<div class="col-lg-2">
<button class="btn btn-primary" id="supportDetail" type="button" data-toggle="collapse"
data-target="#tblSupportDetailCollapse" aria-expanded="false"
aria-controls="tblSupportDetailCollapse">
Support Detail
</button>
</div>
</div>
</div>
</div>
</form>
</div>
<link rel="stylesheet" href="{{ url('PublicCssForm/PacslinkCustomcss.min.css') }}">
<script src="{{ url('js/jquery.min.js') }}"></script>
<script src="{{ url('js/moment.min.js') }}"></script>
<script src="{{ url('theme/bootstrap.min.js') }}"></script>
<script src="{{ url('OrderInvoiceJs/FinancialSupport.min.js') }}"></script>
#endsection
As #aynber mentions in his comment to your question, you are not creating or saving a model, which is obviously the main problem here.
I see that you have this line:
$obj = new SessionClass(); which I assume is the model you want to save, but you do nothing with it, and you also overwrite it below your loop.
First of all, you need to have fields fillable on that model and then either save() or create() with data.
You can see an example of it here https://laravel.com/docs/9.x/eloquent#inserts
Simple example:
class Object extends Model
{
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = ['data1', 'data2', 'data3'];
}
You can then use this class to do something like:
$obj = new Object;
$object->save([
'data1' => 'some value',
'data2' => 'some value',
'data3' => 'some value',
])
// You can also do it like, which will create and save it for you.
$obj = Object::create([
'data1' => 'some value',
'data2' => 'some value',
'data3' => 'some value',
]);
If the fields are not described in the $fillable array of the model, they will not be persisted to the database.
i have created the admin panel where im saving every data, the main thing is the user want to add or edit data from admin panel for his site. its like a blog.
first i have done the slider section where im fetching data from admin panel to client site.
this is the slider section code which is working perfectly.
Add file
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ARABIC SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/arabicpost/submit')}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title 1</label>
<input type="text" name="title" class="form-control" id="exampleInputTitle" placeholder="Enter Title 1">
#error('title')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 1</label>
<textarea class="form-control" name="description" id="" cols="30" rows="10" placeholder="Description 1"></textarea>
#error('description')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 1</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12">
Second Banner
</h3>
</div>
<div class="card-body">
<div class="form-group">
<label for="">Title 2</label>
<input type="text" name="title2" class="form-control" id="exampleInputTitle" placeholder="Enter Title 2">
#error('title2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 2</label>
<textarea class="form-control" name="description2" id="" cols="30" rows="10" placeholder="Description 2"></textarea>
#error('description2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 2</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image2" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image2')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
</div></div></div></div>
#endsection
List File
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<div class="card" style="margin-top:5%">
<div class="card-header">
<h2 class="text-center">English Home Section</h2>
<div class="col-sm-12" style="text-align: center; color:green; font-size:20px">{{session('msg')}}</div>
<div class="col-sm-12" style="text-align: center; color:red; font-size:20px">{{session('msgForDelete')}}</div>
</div>
<div class="card-header">
<a class="btn btn-success" href="{{ URL('/admin/post/add')}}">Add Post</a>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="example1" class="table table-bordered table-striped table-responsive">
<thead>
<tr width="100%">
<th width="3%">ID</th>
<th width="10%">Title 1</th>
<th width="23.5%">Description 1</th>
<th width="10%">Title 2</th>
<th width="23.5%">Description 2</th>
<th width="10%">Image 1</th>
<th width="10%">Image 2</th>
<th width="10%">Action</th>
</tr>
</thead>
<tbody>
<?php
// echo '<pre>';
// print_r([$result]);
// die();
?>
#foreach ($result as $list)
<tr>
<td>{{$list->id}}</td>
<td>{{$list->title}}</td>
<td>{{$list->description}}</td>
<td>{{$list->title2}}</td>
<td>{{$list->description2}}</td>
<td><img src="{{ asset('storage/app/public/post/'.$list->image) }}" width="150px"/></td> <td><img src="{{ asset('storage/app/public/post/secondbanner/'.$list->image2) }}" width="150px"/></td>
<td><a class="btn btn-primary" href="{{('/haffiz/admin/post/edit/'.$list->id)}}">Edit</a>
<a class="btn btn-danger" href="{{('/haffiz/admin/post/delete/'.$list->id)}}">Delete</a>
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Title 1</th>
<th>Description 1</th>
<th>Title 2</th>
<th>Description 2</th>
<th>Image 1</th>
<th>Image 2</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div></div></div> </div>
#endsection
edit file
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/admin/post/update/'.$result['0']->id)}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title</label>
<input type="text" name="title" class="form-control" id="exampleInputTitle" value="{{$result['0']->title}}" placeholder="Enter Title">
#error('title')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description</label>
<textarea class="form-control" name="description" id="" cols="30" rows="10" placeholder="Description">{{$result['0']->description}} </textarea>
#error('description')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-body">
<div class="form-group">
<label for="">Title 2</label>
<input type="text" name="title2" class="form-control" id="exampleInputTitle" value="{{$result['0']->title2}}" placeholder="Enter Title">
#error('title2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 2</label>
<textarea class="form-control" name="description2" id="" cols="30" rows="10" placeholder="Description">{{$result['0']->description2}} </textarea>
#error('description2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 2</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image2" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image2')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
</div>
</div>
</div>
</div>
#endsection
its Controller(Post)
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Post extends Controller
{
function listing()
{
$data['result'] = DB::table('posts')->orderBy('id','desc')->get();
return view('admin.post.list',$data);
}
function submit(Request $req)
{
//validation
$req->validate([
'title' => 'required',
'description' => 'required',
'title2' => 'required',
'description2' => 'required',
'image' => 'mimes: jpg,jpeg,png',
'image2' => 'mimes: jpg,jpeg,png'
]);
//storing image
$image=$req->file('image');
$ext = $image->extension();
$file=time().'.'.$ext;
$image->storeAs('public/post',$file);
$image2=$req->file('image2');
$ext2 = $image2->extension();
$file2=time().'.'.$ext2;
$image2->storeAs('public/post/secondbanner',$file2);
//array
$data = array(
'title' => $req->input('title'),
'description' => $req->input('description'),
'title2' => $req->input('title2'),
'description2' => $req->input('description2'),
'image' => $file,
'image2' => $file2,
);
//inserting data
DB::table('posts')->insert($data);
$req->session()->flash('msg','Data has been Added');
return redirect('/admin/post/list');
}
function delete(Request $req , $id)
{
DB::table('posts')->where('id',$id)->delete();
$req->session()->flash('msgForDelete','Data has been Deleted');
return redirect('/admin/post/list');
}
function edit(Request $req , $id)
{
$data['result'] = DB::table('posts')->where('id',$id)->get();
return view('admin.post.edit',$data);
}
function update(Request $req , $id)
{
//validation
$req->validate([
'title' => 'required',
'description' => 'required',
'title2' => 'required',
'description2' => 'required',
'image' => 'mimes: jpg,jpeg,png',
'image2' => 'mimes: jpg,jpeg,png'
]);
//array
$data = array(
'title' => $req->input('title'),
'description' => $req->input('description'),
'title2' => $req->input('title2'),
'description2' => $req->input('description2'),
);
if($req->hasfile('image'))
{
$image=$req->file('image');
$ext = $image->extension();
$file=time().'.'.$ext;
$file2=time().'.'.$ext;
$image->storeAs('public/post/',$file,$file2);
$data['image']=$file;
}
if($req->hasfile('image2'))
{
$image2=$req->file('image2');
$ext = $image2->extension();
$file2=time().'.'.$ext;
$image2->storeAs('public/post/secondbanner',$file2);
$data['image2']=$file2;
}
//updating data
DB::table('posts')->where('id',$id)->update($data);
$req->session()->flash('msg','Data has been Updated');
return redirect('/admin/post/list');
}
}
and this is a controller where im sending data to client site.
<?php
namespace App\Http\Controllers\user;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class EngHafizController extends Controller
{
public function login()
{
return view('user.english.login');
}
public function registration()
{
return view('user.english.registration');
}
public function homefront()
{
return view('user.english.index');
}
public function home()
{
$data['result'] = DB::table('posts')->get();
return view('user.english.index',$data);
}
public function about()
{
$data['aboutresult'] = DB::table('abouts')->get();
return view('user.english.about',$data);
}
public function whyhaffez()
{
return view('user.english.whyhaffez');
}
public function oursheikh()
{
return view('user.english.oursheikh');
}
public function contact()
{
return view('user.english.contact');
}
}
This is all working properly.
lets get to the point. when try to do the same for ABOUT section
it give me the error which is
(Undefined variable: aboutresult (View:C:\xampp\htdocs\haffiz\resources\views\user\english\index.blade.php))
i do the same thing for about section
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AboutController extends Controller
{
function about_listing()
{
$data['aboutresult'] = DB::table('abouts')->orderBy('id','desc')->get();
return view('admin.post.about.aboutlist',$data);
}
function about_submit(Request $request)
{
//validation
$request->validate([
'title3' => 'required',
'heading3' => 'required',
'description3' => 'required',
'image3' => 'mimes: jpg,jpeg,png'
]);
//storing image
$image3=$request->file('image3');
$ext = $image3->extension();
$file=time().'.'.$ext;
$image3->storeAs('public/post/about_image',$file);
//array
$data = array(
'title3' => $request->input('title3'),
'heading3' => $request->input('heading3'),
'description3' => $request->input('description3'),
'image3' => $file,
);
//inserting data
DB::table('abouts')->insert($data);
$request->session()->flash('msg','Data has been Added');
return redirect('/admin/post/about/aboutlist');
}
function about_delete(Request $request , $id)
{
DB::table('abouts')->where('id',$id)->delete();
$request->session()->flash('msgForDelete','Data has been Deleted');
return redirect('/admin/post/list');
}
function about_edit(Request $request , $id)
{
$data['aboutresult'] = DB::table('abouts')->where('id',$id)->get();
return view('admin.post.about.aboutedit',$data);
}
function about_update(Request $request , $id)
{
//validation
$request->validate([
'title3' => 'required',
'heading3' => 'required',
'description3' => 'required',
'image3' => 'mimes: jpg,jpeg,png'
]);
//array
$data = array(
'title3' => $request->input('title3'),
'heading3' => $request->input('heading3'),
'description3' => $request->input('description3'),
);
if($request->hasfile('image3'))
{
$image3=$request->file('image3');
$ext = $image3->extension();
$file=time().'.'.$ext;
$image3->storeAs('public/post/about_image',$file);
$data['image3']=$file;
}
//updating data
DB::table('abouts')->where('id',$id)->update($data);
$request->session()->flash('msg','Data has been Updated');
return redirect('/admin/post/about/aboutlist');
}
}
aboutLIST
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<div class="card">
<div class="card-header">
<h2 >About Section</h2>
<div class="col-sm-12" style="text-align: center; color:green; font-size:20px">{{session('msg')}}</div>
<div class="col-sm-12" style="text-align: center; color:red; font-size:20px">{{session('msgForDelete')}}</div>
</div>
<div class="card-header">
<a class="btn btn-success" href="{{ URL('/admin/post/about/about')}}">Add Post</a>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr width="100%">
<th width="">ID</th>
<th width="10">Title </th>
<th width="40">Heading</th>
<th width="15">Description </th>
<th width="10">Image </th>
<th width="25%">Action</th>
</tr>
</thead>
<tbody>
<?php
// echo '<pre>';
// print_r([$aboutresult]);
// die();
?>
#foreach ($aboutresult as $aboutlist)
<tr>
<td>{{$aboutlist->id}}</td>
<td>{{$aboutlist->title3}}</td>
<td>{{$aboutlist->heading3}}</td>
<td>{{$aboutlist->description3}}</td>
<td><img src="{{ asset('storage/app/public/post/about_image/'.$aboutlist->image3) }}" width="150px" height="100px"/></td>
<td>
<a class="btn btn-primary" href="{{('/haffiz/admin/post/about/aboutedit/'.$aboutlist->id)}}">Edit</a>
<a class="btn btn-danger" href="{{('/haffiz/admin/post/delete'.$aboutlist->id)}}" >Delete</a>
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th width="4">ID</th>
<th width="10">Title </th>
<th width="40">Heading</th>
<th width="15">Description </th>
<th width="10">Image</th>
<th width="25%">Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.card-body -->
</div>
</div>
</div>
#endsection
aboutedit
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Edit About Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/about/aboutlist')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/admin/post/about/update/'.$aboutresult['0']->id)}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title</label>
<input type="text" name="title3" class="form-control" id="exampleInputTitle" value="{{$aboutresult['0']->title3}}" placeholder="Enter Title">
#error('title3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Heading</label>
<input class="form-control" name="heading3" id="" placeholder="Heading" value="{{$aboutresult['0']->heading3}}">
#error('heading3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description </label>
<textarea class="form-control" name="description3" id="" cols="30" rows="10" placeholder="Description ">{{$aboutresult['0']->description3}}</textarea>
#error('description3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image3" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image3')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
</div>
</div>
</div>
</div>
#endsection
this the index file where im fetching
#foreach ($result as $list)
<img src="{{ asset('storage/app/public/post/'.$list->image) }}" class="d-block w-100" alt="...">
<div class="col-12 text-left">
<h1 class="animated slideInDown">{{ $list->title }}</h1>
<svg class="animated slideInDown" width="128" height="9" viewBox="0 0 128 9" fill="none" xmlns="http://www.w3.org/2000/svg">
</svg>
<p class="animated slideInLeft">{{ $list->description }}</p>
Read More
</div>
<div class="carousel-item">
<img src="{{ asset('storage/app/public/post/secondbanner/'.$list->image2) }}" class="d-block w-100" alt="...">
<h1 class="animated slideInDown">{{ $list->title2}}</h1>
<p class="animated slideInLeft">{{ $list->description2 }}</p>
#endforeach
</div>
about section
#foreach($aboutresult as $aboutlist)
<div class="col-xl-7 about-p">
<h5 class="about-welcome">{{$aboutlist->title3}}</h5>
#endforeach
public function home()
{
$data['aboutresult'] = DB::table('abouts')->get();
$data['result'] = DB::table('posts')->get();
return view('user.english.index',$data);
}
I have a user role called vendor which is one level below the super admin. I am trying to pull just the authenticated vendor's records in the index view but haven't had any luck. I can see the table in the view (which shows no records) and I can create a new record view the ui I have created. The fact is, I have no idea how to pull the current authenticated user's vendor records to the view. I am getting no errors in the console. Here are the following files.
in my vendorEmpresaContoller.php here is the index function
class vendorEmpresaController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$empresa = Empresa::where('id', Auth::id())->get();
return view('vendor.empresas.index')->with('empresas', $empresa);
}
Vendor Middle ware
vendorMiddleware.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class VendorMiddleware
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::user()->role_as == 'vendor') {
if (Auth::check() && Auth::user()->isBanned) {
$banned = Auth::user()->isBanned == "1";
Auth::logout();
if ($banned == 1) {
$message = 'Your account has been Banned. Please contact the administrator.';
}
return redirect()->route('login')->with('status', $message)->withErrors(['email' => 'Your account has been Banned. Please contact the administrator.']);
}
return $next($request);
} else {
return redirect('/home')->with('status', 'You are not permitted to access the vendor dashboard');
}
}
}
User.php as my Model
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Cache;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function isUserOnline()
{
return Cache::has('user-is-online' . $this->id);
}
public function empresas()
{
return $this->hasMany('App\Empresa');
}
}
and my Empresa Model (relevant code only)
Empresa.php
public function empresas()
{
return $this->hasMany('App\Empresa');
}
And finally, in my index (the view I am trying to present the records) index.blade.php
#extends('layouts.vendor-admin')
#section('content')
<!-- Start delete modal-->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Borrar</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="/delete-empresa" method="POST" id="deleteForm">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<div class="modal-body mx-3">
<input type="hidden" name="_method" value="DELETE">
<div class="text-center">
<i class="fas fa-exclamation-triangle mb-4" style="color: #ffc107; font-size: 32px;"></i>
</div>
<h3 class="text-center text-uppercase">¿Estás Seguro/a?
</h3>
</div>
<div class="modal-footer d-flex justify-content-center">
<button class="btn btn-primary" data-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-danger">Sí, Borralo!</button>
</div>
</form>
</div>
</div>
</div>
<!--end delete modal-->
<div class="container-fluid mt-5">
<!-- Heading -->
<div class="card mb-4 wow fadeIn">
<!--Card content-->
<div class="card-body d-sm-flex justify-content-between">
<h4 class="mb-2 mb-sm-0 pt-1">
Inicio
<span>/</span>
<span>Empresas Registradas</span>
</h4>
#if (session('status'))
<div class="alert alert-success fade-message" role="alert">
{{ session('status') }}
</div>
#endif
<div class="modal fade" id="modalRegisterForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Añadir Empresa</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="/vendor-empresas" method="POST">
{{ csrf_field() }}
<div class="modal-body mx-3">
<div class="md-form mb-1">
<input type="text" name="erfc" id="orangeForm-erfc" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-erfc">RFC</label>
</div>
<div class="md-form mb-1">
<input type="text" name="enombre" id="orangeForm-enombre" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-enombre">Nombre</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecalle" id="orangeForm-ecalle" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecalle">Calle</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecolonia" id="orangeForm-ecolonia" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecolonia">Colonia</label>
</div>
<div class="md-form mb-1">
<input type="text" name="eciudad" id="orangeForm-eciudad" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-eciudad">Ciudad</label>
</div>
<div class="md-form mb-1">
<input type="text" name="eestado" id="orangeForm-eestado" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-eestado">Estado</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecpostal" id="orangeForm-ecpostal" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecpostal">Codigo Postal</label>
</div>
<div class="md-form mb-1">
<input type="text" name="epais" id="orangeForm-epais" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-epais">País</label>
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="euser" readonly id="orangeForm-euser" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="eregby" readonly id="orangeForm-eregby" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
<button type="submit" class="btn btn-deep-orange">Añadir</button>
</div>
</form>
</div>
</div>
</div>
<div class="text-center">
<i class="fa fa-plus" aria-hidden="true"></i> Añadir
</div>
</div>
</div>
<!-- Heading -->
<!--Grid row-->
<!--Grid column-->
<div class="row">
<!--Card-->
<div class="col-md-12 mb-4">
<!--Card content-->
<div class="card">
<!-- List group links -->
<div class="card-body">
<table id="datatable2" class="table table-bordered">
<thead>
<tr>
<th style="display: none;">ID</th>
<th>RFC</th>
<th>Nombre</th>
<th>Calle</th>
<th>Colonia</th>
<th>Ciudad</th>
<th>Estado</th>
<th>Codigo Postal</th>
<th>País</th>
<th>Acción</th>
</tr>
</thead>
<tbody>
#foreach ($empresas as $empresa)
<tr>
<input type="hidden" name="id" value="{{ $empresa->id }}">
<td style="display: none;">{{ $empresa->id }}</td>
<td>{{ $empresa->erfc }}</td>
<td>{{ $empresa->enombre }}</td>
<td>{{ $empresa->ecalle }}</td>
<td>{{ $empresa->ecolonia }}</td>
<td>{{ $empresa->eciudad }}</td>
<td>{{ $empresa->eestado }}</td>
<td>{{ $empresa->ecpostal }}</td>
<td>{{ $empresa->epais }}</td>
<td>
<div class="text-center">
<a class="badge badge-pill btn-primary px-3 py-2" href="{{ url('edit-empresa/'.$empresa->id) }}">Editar</a>
<a class="delete badge badge-pill btn-danger px-3 py-2">Borrar</a>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- List group links -->
</div>
</div>
<!--/.Card-->
</div>
<!--Grid row-->
</div>
#endsection
#section('scripts')
<script>
$(document).ready(function() {
let table = $('#datatable2').DataTable();
// Start Delete Record
table.on('click', '.delete', function() {
$tr = $(this).closest('tr');
if($($tr).hasClass('child')) {
$tr = $tr.prev('.parent')
}
let data = table.row($tr).data();
console.log(data);
$('#deleteForm').attr('action', '/delete-empresa/'+data[0]);
$('#deleteModal').modal('show');
});
// End Delete Record
});
</script>
<script>
$(document).ready(function($) {
$(function() {
setTimeout(function() {
$('.fade-message').slideUp();
}, 3000);
});
});
</script>
#endsection
Here is the Database showing the record I am trying to retrieve which is user with the id 18.
Since I am new to Laravel (a complete noob) I really appreciate the help in getting the records visible. Thank you in advance for your help.
I am facing undefined variable error when trying to access a variable in my view. I have gone through several solutions out here but none of them has worked for me. I have thoroughly examined everything that could cause this error in mu code and cannot find anything at all, please assist
Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;
use App\Category;
use App\Depot;
use Illuminate\Support\Facades\DB;
use Gloudemans\Shoppingcart\Facades\Cart;
use Auth;
class CheckoutController extends Controller
{
public function index()
{
$allcategories=Category::get();
$delivery_method = DB::table('deliverymethods')
->get();
$cartItems=Cart::content();
return view('checkout.index',['delivery_method'=>$delivery_method],['allcategories'=>$allcategories]);
}
public function deliverymethod()
{
$cartItems=Cart::content();
$allcategories=Category::get();
return view('delivery.index',['cartItems'=>$cartItems],['allcategories'=>$allcategories]);
}
public function billinginfo()
{
$depots=Depot::get();
$cartItems=Cart::content();
$allcategories=Category::get();
return view('billing.index',compact('cartItems'),['allcategories'=>$allcategories],['depots'=>$depots]);
}
public function shipping(Request $request)
{
$user_id=Auth::user()->id;
$shippingaddress=DB::table('shippingaddresses')
->select('shippingaddresses.*')
->where('user_id',$user_id)
->get();
$cartItems=Cart::content();
$allcategories=Category::get();
return view('shipping.index',['cartItems'=>$cartItems],['allcategories'=>$allcategories],['shippingaddress'=>$shippingaddress]);
}
}
My View
#extends('home.base')
#section('action-content')
<div class="container">
<div class="container" id="cart-window">
<div class="row">
<div class="col-lg-12" id="cart-header">
<h3>Billing & Shipping Details <span class="cart-return pull-right"><i class="ionicons ion-ios-cart"></i> Back to Cart</h3>
</div>
</div>
<div class="row">
<div class="col-lg-9">
#if(Cart::Count()==0)
<div class="row">
<div class="col-lg-12" id="empty-cart">
<p>Your cart is currently empty</p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
Return to Shop
</div>
</div>
#else
<div class="card detail" id="delivery-card">
<div class="card-header">
</div>
<div class="card-body">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-lg-6">
<h5><strong>Existing Addresses</strong></h5>
</div>
<div class="col-lg-6">
<select class="select2 form-control" id="newAddress">
<option selected disabled>Please Select Delivery Address</option>
<option value="0">Add New Address</option>
#foreach($shippingaddress as $depot)
<option value="{{$depot->depot_name}}">{{$depot->depot_name}}</option>
#endforeach
<option>LIGHt</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
#endif
</div>
<div class="col-lg-3">
#if(Cart::Count()>0)
<div class="card detail">
<div class="card-header">
</div>
<div class="card-body">
<p class="card-text" id="cart-summary">
Order Summary
</p>
<hr/>
<div class="row">
<div class="col-sm-6">
{{Cart::Count()}}
</div>
<div class="col-sm-6">
#if(Cart::Count()==1)
Item
#else
Items
#endif
</div>
</div>
<hr/>
<div class="row">
<div class="col-sm-6">
<p>
Subtotal
</p>
<p>
VAT (15%)
</p>
<p>
Total to Pay
</p>
</div>
<div class="col-sm-6" id="cart-totals">
<p>
R{{Cart::subtotal()}}
</p>
<p>
R{{Cart::tax()}}
</p>
<p>
R{{Cart::total()}}
</p>
</div>
</div>
<hr/>
<div class="row">
<div class="col-12 continue-btn">
Continue
</div>
</div>
{{-- <hr>
<div class="row" id="delivery-method">
<select class="form-control select2" id="delivery_method" name="del">
<option value="0" selected disabled>Select Delivery Method</option>
#foreach ($delivery_method as $item)
<option value="{{$item['delivery_method']}}">{{$item['delivery_method']}} R{{$item['price']}}</option>
#endforeach
</select>
</div> --}}
</div>
{{-- <div class="card-footer" id="cart-footer">
<div class="delivery_type">
<strong>Checkout</strong>
</div>
{{-- <div class="delivery_type2">
<strong>Checkout 2</strong>
</div> --}}
{{-- </div> --}}
</div>
<div class="card order-review">
<div class="card-body">
<p class="card-text" id="cart-summary">
Order Review
</p>
<div class="row">
<div class="col-sm-12">
<p><strong>Delivery Method</strong> <span class="change-del pull-right">Change</span></p>
<p>Delivery</p>
</div>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
<!-- NewAddressModal -->
<!-- Modal -->
<div class="modal fade show" id="newAddressModal" style="display: none;" aria-modal="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Default Modal</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
#push('custom_scripts')
<script type="text/javascript">
$(document).ready(function() {
{{-- $("#newAddress").change(function() {
var curVal = $("#newAddress option:selected").val();
if (curVal.indexOf('#newAddressModal') == 0){
$('#newAddressModal').modal('show');
}
}); --}}
$("#newAddress").on("change", function () {
$modal = $('#newAddressModal');
if($(this).val() === '0'){
$modal.modal('show');
}
});
});
</script>
#endpush
#endsection
Error Image
Error Image
Try grouping Multiple collection into one array, Then send it to the view like this:
$viewData = [
'cartItems' => $cartItems,
'allcategories' => $allcategories,
'shippingaddress' => $shippingaddress
];
return View::make('shipping.index')->with($viewData);
In an html page, I would like to recover the value of an amount and can change the value only in my admin panel.
In the file navbar.blade.php I have 250 which is the amount to edit for the example.
<div class="header-widgets hidden-xs" style="padding:0px;padding-top: 60px;">
<div id="text-3" class="widget widget_text">
<div class="textwidget">
<div class="info-icon">
<img src="/img/time.png">
<span style="font-size: 22px;color: #0d3863;font-weight: bold;"> 250</span>
</div>
</div>
</div>
</div>
I just seek to edit the amount (250) ...
In my Controller named tarrifcontroller I have that.
public function edit(Tariff $tariff)
{
return view('admin.tariffs.edit', compact('tariff'));
}
public function update(Request $request, Tariff $tariff)
{
$tariff->valeur = strip_tags($request->input('amount'));
$tariff->save();
return redirect('/tariffs');
}
In my edit.blade.php I have that
#section('content')
<div class="px-content">
<div class="page-header">
<div class="row">
<div class="col-md-4 text-xs-center text-md-left text-nowrap">
<h1><i class="px-nav-icon ion-android-apps"></i>Tarif {{$tariff->id}} </h1>
</div>
<hr class="page-wide-block visible-xs visible-sm">
<!-- Spacer -->
<div class="m-b-2 visible-xs visible-sm clearfix"></div>
</div>
</div>
<div class="row">
<div class="panel">
<div class="panel-body">
<div class="table-responsive">
<form class="panel-body" action="/tariff/edit/{{$tariff->id}}" method="POST">
#csrf
<fieldset class="form-group">
<label for="form-group-input-1">Amount</label>
<input type="text" name="amount" class="form-control" id="form-group-input-1" value="{{$tariff->amount}}">
</fieldset>
<button type="submit" class="btn btn-primary pull-right">MAJ</button>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
My problem is now in navbar.blade.php how should I do that 250 can interact with my edit / update function?
<span style="font-size: 22px;color: #0d3863;font-weight: bold;"> 250</span>
Thank you
I don't have experience with laravel but i guess like any other php framework you can echo variable from controller to view
<span style="font-size: 22px;color: #0d3863;font-weight: bold;"> <?php echo $variable ?></span>
after some googling: You can pass data to the view using the with method.
return View::make('blog')->with('posts', $posts);