I am trying to use the Create button to add an element but the recovery doesn't work. I don't have an error message... However my Delete button works well.
In my AdminController I have this:
class AdminController extends Controller
{
public function getHome(){
$devis = Devis::all()->sortByDesc("created_at");
return view('admin.devis.home', compact('devis'));
}
public function destroy(Devis $devis)
{
$devis->delete();
return redirect('/admin');
}
public function create()
{
return view('admin.devis.create');
}
public function store(Request $request)
{
$request->validate([
'firstname' => 'required',
'lastename' => 'required'
]);
Devis::create($request->all());
return redirect()->route('admin.devis.home')
->with('success', 'un étudiant a été crée');
}
}
I think the Controller is correct.
In my folder View => Admin => Devis I have 2 files:
Home.blade.php
#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>Listing </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">
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastename</th>
<a class="btn btn-sm btn-success" href="{{ route('devis.create') }}">Create</a>
</tr>
</thead>
#foreach($devis as $item)
<tr>
<td> {{$item->firstname}} </td>
<td> {{$item->lastname}} </td>
<td> <span class="left ion-close"></span></td>
</tr>
#endforeach
</table>
</div>
</div>
</div>
</div>
</div>
#endsection
And create.blade.php
#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>Devis</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="/devis" method="POST">
#csrf
<fieldset class="form-group">
<label for="form-group-input-1">FirstName</label>
<input type="text" name="firstname" class="form-control" id="form-group-input-1">
</fieldset>
<fieldset class="form-group">
<label for="form-group-input-1">Lastname</label>
<input type="text" name="lastname" class="form-control" id="form-group-input-1" >
</fieldset>
<button type="submit" class="btn btn-primary pull-right">Create</button>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
In the routes folder I have this
route::resource('devis','AdminController');
Route::post('/devis', 'AdminController#store');
Route::get('/devis/delete/{devis}', 'AdminController#destroy');
I thank you for your help.
Ok, First, sometimes you use lastname, sometimes you use lastename and validator doesn't recognize because they are different names.
Second, you don't see any errors because you haven't implemented a flash_message to see the errors inside the session.
$request->validate([
'firstname' => 'required',
'lastename' => 'required'
]);
<input type="text" name="lastname" class="form-control" id="form-group-input-1" >
Actually you have issue in the naming when you are validating it through the validate function like below:
it should be
$request->validate([
'firstname' => 'required',
'lastname' => 'required'
]);
instead of:
$request->validate([
'firstname' => 'required',
'lastename' => 'required'
]);
you are using lastename instead of lastname.
Validator method actually should have correct indexes otherwise it will not stored in database.
hope it will help.
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.
This is my livewire component class code
This is my livewire component class code
This is my livewire component class code This is my livewire component class code
<?php
namespace App\Http\Livewire;
use Livewire\WithPagination;
use Livewire\Component;
use App\Models\student;
class Students extends Component
{
public $selectData= true;
public $createtData= false;
public $updateData= false;
public $name;
public $email;
public $country;
public $studentID;
public $edi_name;
public $edi_email;
public $edi_country;
public $total_student;
use WithPagination;
public function render()
{ $this->total_student=student::get();
$student=student::orderBy('studentID','ASC')->paginate(100);
return view('livewire.students',['student'=>$student])->extends('layouts.app');
}
public function showform()
{
dd('kawish');
$this->selectData=false;
$this->createtData=true;
}
public function resetField()
{
$this->$name="";
$this->$email="";
$this->$country="";
$this->studentID;
$this->edi_name="";
$this->edi_email="";
$this->edi_country="";
}
public function create()
{
$student=new student();
$this->validate([
'name'=>'required',
'email'=>'required',
'country'=>'required',
]);
//This is my livewire
$student->name=$this->name;
$student->email=$this->email;
$student->country=$this->country;
$result =$student->save();
$this->resetField();
$this->selectData=true;
$this->createtData=false;
}
public function edit($studentID)
{
$this->selectData=false;
$this->updateData=true;
$student= student::findorFail($studentID);
$this->studentID=$student->studentID;
$this->edi_name=$student->name;
$this->edi_email=$student->email;
$this->edi_country=$student->country;
}
public function update($studentID)
{
$student= student::findorFail($studentID);
$this->validate([
'edi_name'=>'required',
'edi_email'=>'required',
'edi_country'=>'required',
]);
$student->name=$this->edi_name;
$student->email=$this->edi_email;
$student->country=$this->edi_country;
$result =$student->save();
$this->resetField();
$this->selectData=true;
$this->updateData=false;
}
public function delete($studentID){
$student= student::findorFail($studentID);
$result=$student->delete();
}
}
//This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire
This is my view for the same class
This is my view for the same classT his is my view for the same class
<div>
#section('title','students')
#section('content')
<div class=" container">
<div class="mt-5">
<div class=" card">
<div class=" card-header">
<div class=" d-flex justify-content-between">
<h3>users ({{count($total_student)}})</h3>
<div>
<button wire:click='showform' class="btn btn-success">Add User</button> *//error
</div>
</div>
</div>
</div>
</div>
List item
{{-- table list --}}
#if ($selectData==true)
<div class=" table-responsive mt-5">
<table class="table table-bordered">
<thead>
<tr class="bg-dark text-light">
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Country</th>
<th>Options</th>
</tr>
</thead>
#forelse ( $student as $item )
<tbody>
<tr>
<td>{{ $item->studentID }}</td>
<td>{{ $item->name }}</td>
<td>{{ $item->email }}</td>
<td>{{ $item->country }}</td>
<td>
<button class="btn btn-success" wire:click="edit({{$item->studentID }})">Edit</button>
<button class="btn btn-danger" wire:click="delete({{$item->studentID }})">Delete</button>
</td>
</tr>
#empty
<tr>
<td>
<p class="text-danger">#record not found</p>
</td>
</tr>
</tbody>
#endforelse
</table>
</div>
#endif
{{-- create data --}}
#if ($createtData==true)
<div class="row">
<div class=" col-xl-6 col-md-8 col-sm-12 offset-xl-3 offset-md-2 offset-sm-0">
<div class="card">
<div class="card-header">
<h1>Add Data</h1>
</div>
<form action="" class="mt-5" wire.submit.prevent='create'>
<div class="card-body">
<div class=" form-group">
<label for="name">Enter Name</label>
<input wire:model='name' type="text" name="name" id="name" class="form-control form-control-lg">
<span class="text-danger">
#error('name')
{{ $message }}
#enderror
</span>
</div>
<div class=" form-group">
<label for="email">Enter Email</label>
<input wire:model='email' type="email" name="email" id="email" class="form-control form-control-lg">
#error('email')
{{ $message }}
#enderror
</div>
<div class=" form-group">
<label for="country">Enter Country</label>
<input wire:model='country' type="text" name="country" id="country" class="form-control form-control-lg">
#error('country')
{{ $message }}
#enderror
</div>
</div>
<div class=" card-footer">
<button class="btn btn-success">Save</button>
</div>
</form>
</div>
</div>
</div>
#endif
{{-- update data --}}
#if ($updateData==true)
<div class="row mt-5">
<div class=" col-xl-6 col-md-8 col-sm-12 offset-xl-3 offset-md-2 offset-sm-0">
<div class="card">
<div class="card-header">
<h1>Update Data</h1>
</div>
<form action="" class="mt-5" wire.submit.prevent='update({{$studentID}})'>
<div class="card-body">
<div class=" form-group">
<label for="name">Enter Name</label>
<input wire:model="edi_name" type="text" name="name" id="name" class="form-control form-control-lg">
<span class="text-danger">
#error('edi_name')
{{ $message }}
#enderror
</span>
</div>
<div class=" form-group">
<label for="email">Enter Email</label>
<input wire:model="edi_email" type="email" name="email" id="email" class="form-control form-control-lg">
<span class="text-danger">
#error('edi_email')
{{ $message }}
#enderror
</span>
</div>
<div class=" form-group">
<label for="country">Enter Country</label>
<input wire:model="edi_name" type="text" name="country" id="country" class="form-control form-control-lg">
<span class="text-danger">
#error('edi_country')
{{ $message }}
#enderror
</span>
</div>
</div>
<div class=" card-footer">
<button class="btn btn-success">Update</button>
</div>
</form>
</div>
</div>
</div>
#endif
</div>
#endsection
//This is my livewire //This is my livewire
my layout codes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>#yield('title')</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
#livewireStyles
</head>
<body>
<div class="container-fluid bg-dark">
<div class=" container p-4">
<h2 class="text-center text-white">Laravel Livewire Crud</h2>
</div>
</div>
<div>
#yield('content')
</div>
#livewireScripts
</body>
</html>
`**my routing**`
<?php
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use App\Http\Livewire\Students;
// Route::view('/', 'app');
Route::get('/', Students::class);
here its endsssss
here its endsssss
Remove the #section in your component view. livewire component needs to start with a . You can extend your section inside the component to have it like this
public function render()
{ $this->total_student=student::get();
$student=student::orderBy('studentID','ASC')->paginate(100);
return view('livewire.students',['student'=>$student])->extends('layouts.app')->slot('content");
}
You can have your component view like this
<div class=" container">
<div class="mt-5">
<div class=" card">
<div class=" card-header">
<div class=" d-flex justify-content-between">
<h3>users ({{count($total_student)}})</h3>
<div>
<button wire:click='showform' class="btn btn-success">Add User</button> *//error
</div>
</div>
</div>
</div>
</div>
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);
}
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';
}
I succeeded the step "create" barring the overview.
My recordings are saved on PhpMyAdmin but not on my page index.blade.php I don't understand why ? I made several refreshments even so.
Here is my file AdminController.php
class AdminController extends Controller
{
public function index(){
/*$devis = Devis::all()->sortByDesc("created_at");
return view('admin.home', compact('devis'));*/
$students = Student::first()->paginate(5);
return view('student.index', compact('students'))
->with('i', (request()->input('page',1)-1)*5);
}
public function create()
{
return view('student.create');
}
public function store(Request $request)
{
$request->validate([
'firstname' => 'required',
'lastname' => 'required'
]);
Student::create($request->all());
return redirect()->route('student.index')
->with('success', 'save');
}
}
In my folder VIEWS with another folder which is Student which has 2 files:
Index.blade.php
#extends('student.template.master')
#section('left_menu')
#include('student.template.left_menu', array('current' => 'home'))
#endsection
#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>List </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">
<table class="table">
<a class="btn btn-sm btn-success" href="{{ route('student.create') }}">Create</a>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
#foreach($students as $item)
<tr>
<td> {{$item->firstname}}</td>
<td> {{$item->lastname}} </td>
<td> <span class="left ion-close"></span></td>
</tr>
#endforeach
</table>
</div>
</div>
</div>
</div>
</div>
#endsection
And create.blade.php
#extends('student.template.master')
#section('left_menu')
#include('student.template.left_menu', array('current' => 'home'))
#endsection
#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>Devis</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="{{route('student.store')}}" method="POST">
#csrf
<fieldset class="form-group">
<label for="form-group-input-1">Firstname</label>
<input type="text" name="firstname" class="form-control" id="form-group-input-1">
</fieldset>
<fieldset class="form-group">
<label for="form-group-input-1">Lastname</label>
<input type="text" name="lastname" class="form-control" id="form-group-input-1" >
</fieldset>
Back
<button type="submit" class="btn btn-sm btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
Do you have an idea please ? I am really stuck.
first() returns an instance of the class Student, you can't paginate on it. change
public function index(){
/*$devis = Devis::all()->sortByDesc("created_at");
return view('admin.home', compact('devis'));*/
$students = Student::first()->paginate(5);
return view('student.index', compact('students'))
->with('i', (request()->input('page',1)-1)*5);
}
to
public function index(){
/*$devis = Devis::all()->sortByDesc("created_at");
return view('admin.home', compact('devis'));*/
$students = Student::paginate(5);
return view('student.index', compact('students'))
->with('i', (request()->input('page',1)-1)*5);
}
In Laravel, when you use paginate(), it also comes with links() function. So all you needed to do was to pass the variable in the controller, as below:
public function index(){
$students = Student::get()->paginate(5);
return view('student.index', compact('students'));
}
Now, in index.blade.php, just reference the links() function:
{{ $students->links() }}