Unable to pull authenticated user records to view - Laravel - php

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.

Related

How do I get two modals to work on the same page?

I have a food ordering web app in PHP laravel 5.8. The items modal is working fine with the following code but when I am trying to display the deals modal in the same manner, it does not work at all. I am sharing my blade files. The "show.blade.php" file displays the entire front page where these modals have to be shown to the customer. The "modal.blade.php" file is where the modals are defined and their data is coming from the "show.blade.php" page. The first div in the modals file is the one that I want to work and the second is the one that is currently working fine. You can ignore the last modal div.
show.blade.php
#extends('layouts.front', ['class' => ''])
<?php
use Carbon\Carbon;
use App\User;
$name = new User();
?>
#section('content')
#include('restorants.partials.modals')
<section class="section pt-lg-0" id="restaurant-content" style="padding-top: 0px">
<input type="hidden" id="rid" value="{{ $restorant->id }}" />
<div class="container container-restorant">
<hr>
#if ($deals)
<div class="owl-carousel owl-theme owl-loaded">
<div class="owl-stage-outer">
<div class="owl-stage">
<h1>Deals</h1>
#foreach ($deals as $deal)
<div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
<div class="owl-item">
<div id="addToCart1">
<div class="strip">
<figure style="border-radius: 3rem">
<a onClick="setCurrentDeal({{ $deal->id }})" href="javascript:void(0)"><img
src="{{ $deal->image_url }}_thumbnail.jpg" loading="lazy"
data-src="{{ config('global.restorant_details_image') }}"
class="img-fluid lazy" alt=""></a>
</figure>
<span class="res_title"><b><a onClick="setCurrentDeal({{ $deal->id }})"
href="javascript:void(0)">{{ $deal->name }}</a></b></span><br />
<span class="res_description">{{ $deal->description }}</span><br />
<div class="d-flex justify-content-between">
<div>
#php
$dealItems = [];
$dealItems = App\DealItem::where('deal_id', $deal->id)->get();
#endphp
#foreach ($dealItems as $it)
<h6><strong>{{ $it->item->name }}</strong></h6>
#endforeach
</div>
<h6 class="text-success"><strong>Price:{{ $deal->price }}</strong></h6>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="owl-dots">
<div class="owl-dot active"><span></span></div>
<div class="owl-dot"><span></span></div>
<div class="owl-dot"><span></span></div>
</div>
</div>
#endforeach
#endif
</div>
#section('js')
<script>
$(function() {
$('.owl-carousel').owlCarousel({
margin: 50,
autoplay: true,
loop: true
});
});
var deals = [];
var currentDeal = null;
var currentDealSelectedPrice = null;
var lastAdded = null;
var CASHIER_CURRENCY = "<?php echo env('CASHIER_CURRENCY', 'usd'); ?>";
var LOCALE = "<?php echo App::getLocale(); ?>";
/*
* Price formater
* #param {Nummber} price
*/
function formatPrice(price) {
var formatter = new Intl.NumberFormat(LOCALE, {
style: 'currency',
currency: CASHIER_CURRENCY,
});
var formated = formatter.format(price);
return formated;
}
function setCurrentDeal(id) {
var deal = deals[id];
currentDeal = deal;
$('#modalDealTitle').text(deal.name);
$('#modalDealName').text(deal.name);
$('#modalDealPrice').html(deal.price);
$('#modalDealID').text(deal.id);
$("#modalDealImg").attr("src", deal.image);
$('#modalDealDescription').html(deal.description);
//Normal
currentDealSelectedPrice = deal.priceNotFormated;
// $('#variants-area').hide();
$('.quantity-area').show();
$('#dealModal').modal('show');
}
<?php
$deals =[];
foreach ($deals as $deal){
$theArray = [
'name' => $deal->name,
'id' => $deal->id,
'priceNotFormated' => $deal->price,
'price' => #money($deal->price, env('CASHIER_CURRENCY', 'usd'), true) . '',
'image' => $deal->logom,
'description' => $deal->description,
];
echo 'deals[' . $deal->id . ']=' . json_encode($theArray) . ';';
}
?>
<script>
$(document).ready(function() {
$("#addToCart1").show();
// $('#exrtas-area').show();
$('.quantity-area').show();
});
</script>
#endsection
modals.blade.php
<div class="modal fade" id="dealModal" z-index="9999" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="modalDealTitle" class="modal-title" id="modal-title-new-item"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="row">
<div class="col-sm col-md col-lg col-lg text-center">
<img id="modalDealImg" src="" width="295px" height="200px">
</div>
<div class="col-sm col-md col-lg col-lg">
<input id="modalDealID" type="hidden"></input>
<span id="modalDealPrice" class="new-price"></span>
<p id="modalDealDescription"></p>
</div>
<div class="offset-md-6 col-md-6">
#if(!config('app.isqrsaas'))
<div class="quantity-area">
<div class="form-group">
<br />
<label class="form-control-label" for="quantity">{{ __('Quantity') }}</label>
<input type="number" name="quantity" id="quantity" class="form-control form-control-alternative" placeholder="{{ __('1') }}" value="1" required autofocus>
</div>
<div class="quantity-btn float-right">
<div id="addToCart1">
<button class="btn btn-primary" v-on:click='addToCartAct'
<?php
if(auth()->user()){
if(auth()->user()->hasRole('client')) {echo "";} else {echo "disabled";}
}else if(auth()->guest()) {echo "";}
?>
>{{ __('Add To Cart') }}</button>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="productModal" z-index="9999" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="modalTitle" class="modal-title" id="modal-title-new-item"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-body px-lg-5 py-lg-5">
<div class="row">
<div class="col-sm col-md col-lg col-lg text-center">
<img id="modalImg" src="" width="295px" height="200px">
</div>
<div class="col-sm col-md col-lg col-lg">
<input id="modalID" type="hidden"></input>
<span id="modalPrice" class="new-price"></span>
<p id="modalDescription"></p>
<div id="variants-area">
<label class="form-control-label">{{ __('Select your options') }}</label>
<div id="variants-area-inside">
</div>
</div>
</div>
<div class="col-md-12">
<div id="exrtas-area">
<br />
<label class="form-control-label h4" for="quantity">{{ __('Extras') }}</label>
<div class="row" id="exrtas-area-inside"></div>
</div>
</div>
<div class="offset-md-6 col-md-6">
#if(!config('app.isqrsaas'))
<div class="quantity-area">
<div class="form-group">
<br />
<label class="form-control-label" for="quantity">{{ __('Quantity') }}</label>
<input type="number" name="quantity" id="quantity" class="form-control form-control-alternative" placeholder="{{ __('1') }}" value="1" required autofocus>
</div>
<div class="quantity-btn float-right">
<div id="addToCart1">
<button class="btn btn-primary" v-on:click='addToCartAct'
<?php
if(auth()->user()){
if(auth()->user()->hasRole('client')) {echo "";} else {echo "disabled";}
}else if(auth()->guest()) {echo "";}
?>
>{{ __('Add To Cart') }}</button>
</div>
</div>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

This my laravell livewire project my all click function is not working but i render data on screen properly. how can i fix it?

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>

Laravel 8 & Livewire Events not working well

i'm developing an application with laravel 8 and livewire.
I've created in the view gestionale.blade.php three component (table) with the following operation.
The first table is populated when the page is loaded, then a row is selected and the second table is populated with a click event, finally by clicking a row in the second table the third table is populated.
From the Livewire documentation I used the events, but I only have the correct functioning of the first one, that is, clicking on the first table populates the second, but then clicking a row on the second I get nothing.
I entered a dump & die inside the code and I just don't get to raise the event in the second table.
This is my code:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Http\Request;
use App\Models\MinutaArticolo;
use Livewire\WithPagination;
use Illuminate\Support\Facades\DB;
use App\Tenant;
class TableArticoliContent extends Component
{
//Dichiariamo il listener degli eventi
protected $listeners = ['getArticoli' => 'getArticoli'];
protected $connection = null;
public $articoli = null;
protected $paginationTheme = 'bootstrap';
public function mount(Request $request) {
if(null !== $request->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
}
// Funzione richiamata dal componente livewire e che ritorna gli articoli
// a seconda dell'id partita passato
public function getArticoli($id_partita) {
if(null !== request()->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
$this->articoli = MinutaArticolo::on($this->connection)->where('id_minuta_partita', '=', $id_partita)->paginate(15)->toArray();
}
public function render()
{
return view('livewire.table-articoli-content')
->with('articoli', $this->articoli);
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Http\Request;
use App\Models\MinutaArticolo;
use Livewire\WithPagination;
use Illuminate\Support\Facades\DB;
use App\Tenant;
class TableArticoli extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function render() {
return view('livewire.table-articoli');
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use App\Models\AnagraficaSoggetto;
class TablePraticheContent extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
protected $connection = null;
public $pratiche = null;
protected $listeners = ['filtri' => 'renderWithFilter'];
public function mount(Request $request) {
// Setto la connessione
if(null !== $request->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
// Recupero i dati da renderizzare
$anagrafica = new AnagraficaSoggetto();
$anagrafica->setConnection($this->connection);
$this->pratiche = $anagrafica->select(
'denominazioneSoggetto',
'anagrafica_soggetto.codiceFiscale',
'indirizzoPOSTA',
'tipologia_imposta.descrizione_sintetica',
'importoCarico as carico',
'importoResiduo as residuo',
'pagatoNormale as riscosso',
'pagatoDiscarico as sgravio',
'data_assegnazione',
'username as collaboratore',
'minuta_partita.id',
'minuta_partita.id_minuta as id_minuta',
'partita_pagamenti.progressivoRiscossione',
'partita_pagamenti.agenteRiscossione'
)->distinct()
->join('minuta_partita', 'minuta_partita.id_soggetto', '=', 'anagrafica_soggetto.id')
->join('users', 'minuta_partita.id_user', '=', 'users.id', 'left outer')
->join('partita_pagamenti', 'partita_pagamenti.id_minuta_partita', '=', 'minuta_partita.id', 'left outer')
->join('tipologia_imposta', 'minuta_partita.id_tipologia_imposta', '=', 'tipologia_imposta.id')
->paginate(15)->toArray();
}
//funzione per triggerare l'evento onclick sulla tabella pratiche
public function clickPartiteTrigger($id) {
$this->emit('getPartite', $id);
$this->render = false;
}
public function render() {
return view('livewire.table-pratiche-content')
->with('pratiche', $this->pratiche);
}
public function renderWithFilter($filtered){
$this->pratiche = $filtered;
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use App\Models\AnagraficaSoggetto;
class TablePratiche extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function render() {
return view('livewire.table-pratiche');
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\MinutaPartita;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Tenant;
class TablePartiteContent extends Component
{
//Dichiariamo il listener degli eventi
protected $listeners = ['getPartite' => 'getPartite',
'filtri_partite' => 'renderWithFilter'];
protected $connection = null;
public $partite = null;
protected $paginationTheme = 'bootstrap';
public function mount(Request $request) {
if(null !== $request->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
}
//funzione per triggerare l'evento onclick sulla tabella partite
public function clickArticoliTrigger($id) {
dd($id);
$this->emit('getArticoli', $id);
$this->render = false;
}
// Funzione richiamata dal componente livewire e che ritorna le partite
// a seconda dell'id pratica passato
public function getPartite($id_minuta) {
if(null !== request()->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
$this->partite = MinutaPartita::on($this->connection)->where('id_minuta', '=', $id_minuta)->paginate(15)->toArray();
}
public function render() {
return view('livewire.table-partite-content')
->with('partite', $this->partite);
}
public function renderWithFilter($filtered){
$this->partite = $filtered;
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\MinutaPartita;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Tenant;
class TablePartite extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function render() {
return view('livewire.table-partite');
}
}
and this is my component in which i've the event which must make me populate the third table
<tbody id="partite_result">
#if (!empty($partite))
#foreach ($partite['data'] as $pt)
<tr wire:click="clickArticoliTrigger({{ $pt['id']}})">
<td>{{ $pt['annoRuolo'] }}</td>
<td>{{ $pt['numeroRuolo'] }}</td>
<td>{{ $pt['agenteRiscossione'] ?? ''}}</td>
<td>{{ $pt['annoRif'] ?? '' }}</td>
<td>{{ $pt['tipoImposta'] ?? '' }}</td>
<td>{{ $pt['id_minuta_partita'] ?? '' }}</td>
<td>{{ $pt['importoCarico'] }}</td>
<td>{{ $pt['pagatoNormale'] }}</td>
<td>{{ $pt['pagatoDiscarico'] }}</td>
<td>{{ $pt['importoResiduo'] }}</td>
<td>{{ $pt['proceduraEsecutiva'] }}</td>
<td>{{ $pt['importoInesigibilita'] }}</td>
<td>{{ $pt['stato'] ?? ''}}</td>
</tr>
#endforeach
#endif
</tbody>
Can someone have any tips or advice to help me? Thanks to all :-)
EDIT (this is my component code):
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Partite</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example5" class="display" style="min-width: 845px">
<thead>
<tr>
<th>Anno ruolo</th>
<th>Numero ruolo</th>
<th>Agente Riscossione</th>
<th>Anno imposta</th>
<th>Tipo imposta</th>
<th>Partita</th>
<th>Carico</th>
<th>Riscosso</th>
<th>Sgravio</th>
<th>Residuo</th>
<th>Peocedura</th>
<th>Inesigibile</th>
<th>Stato</th>
</tr>
</thead>
<livewire:table-partite-content />
<livewire:tbl-partite-footer-filter />
</table>
</div>
</div>
</div>
</div>
</div>
Clearer code:
I've this route: Route::get('/gestionale', [App\Http\Controllers\GestionaleController::class, 'index']);
And i go in the view blade called gestionale.blade.php and in this view i've my three livewire component.
The code of the view gestionale.blade.php is:
{{-- Extends layout --}}
#extends('layout.layout2')
{{-- Content --}}
#section('content')
<div class="container-fluid">
<div class="row page-titles mx-0">
<div class="col-sm-6 p-md-0">
<div class="welcome-text">
<h4>Benvenuto sul Gestionale</h4>
<span>Qui sono listate pratche, partite e articoli</span>
</div>
</div>
</div>
<!-- import del componente gestionale header filter per i filtri -->
<livewire:gestionale-header-filter>
<!-- fine import del componente gestionale header filter -->
<hr/>
<!-- import dei component livewire (tab: partite, pratiche, articoli) -->
<livewire:table-pratiche /> // first component (event on this works)
<hr/>
<livewire:table-partite /> // second component (in this, the event not works)
<hr/>
<livewire:table-articoli /> // third component
<!-- fine dell'import dei component livewire (tab: partite, pratiche, articoli) -->
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<!-- button per l'apertura dei modal -->
<div class="btn-group">
<button type="button" class="btn btn-primary mb-2" data-toggle="modal" data-target="#PagamentoLongModal">Aggiungi pagamento</button>
<button type="button" class="btn btn-primary mb-2" data-toggle="modal" data-target=".bd-example-modal-lg">Aggiungi assegnatario</button>
<button type="button" class="btn btn-primary mb-2" data-toggle="modal" data-target="#ShowPagamentiModal">Pagamenti</button>
<button type="button" class="btn btn-primary mb-2" data-toggle="modal" data-target="#ProcedureInesigibilitaModal">Procedure/Inesigibilità</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Inizio dei modal per gestire le azioni del gestionale -->
<!-- modal per l'inserimento di un pagamento -->
<div class="modal fade" id="PagamentoLongModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Aggungi un pagamento</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere l'azione -->
<div class="basic-form">
<form method="POST" action="#">
#csrf
<div class="form-group row">
<label class="col-sm-3 col-form-label">Ente</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Ente" value="" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Partita</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Partita" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Anno Rif.</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Anno Riferimento" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Anno</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Anno" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Numero</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Numero" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Carico</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Carico" disabled>
</div>
</div>
<hr/>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Tipologia</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Tipologia">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Imposta</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Imposta">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Decimali</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Decimali imposta" maxlenght="2">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Mora</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Mora">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Decimali</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Decimali mora" maxlength="2">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Data Pagamento</label>
<div class="col-sm-9">
<input type="date" class="form-control input-rounded" placeholder="Email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Data Registrazione</label>
<div class="col-sm-9">
<input type="date" class="form-control input-rounded" placeholder="Email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Note</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Email" minlength="3" maxlength="255">
</div>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary">Salva</button>
</div>
</div>
</div>
</div>
<!-- modal per l'inserimento di un assegnatario -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Aggiungi un assegnatario</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere l'azione -->
<form method="POST" action="#">
<div class="form-group row">
<div class="form-group">
<label>Seleziona assegnatari (tieni premuto shift per una selezione multipla):</label>
<select multiple class="form-control input-rounded" id="sel2">
#if(!empty($users))
#foreach($users as $u)
<option value="{{$u->id}}">{{$u->username}}</option>
#endforeach
#endif
</select>
</div>
<div class="form-group">
<label class="col-sm-12 col-form-label">Data Assegnazione</label>
<div class="col-sm-12">
<input type="date" class="form-control input-rounded" placeholder="Data Assegn.">
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary">Salva</button>
</div>
</div>
</div>
</div>
<!-- modal per visualizzare i pagamenti associati alla partita -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="ShowPagamentiModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Pagamenti associati alla partita</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere il corpo del body -->
<p>Body da aggiungere, da capire i dati da mostrare a video</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary"><i class="fa fa-print" aria-hidden="true"></i> Stampa</button>
</div>
</div>
</div>
</div>
<!-- modal per visualizzare le procedure e le inesigibilita associati alla partita -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="ProcedureInesigibilitaModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Procedure e Inesigibilità</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere il corpo del body -->
<p>Body da aggiungere, da capire i dati da mostrare a video</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary"><i class="fa fa-print" aria-hidden="true"></i> Stampa</button>
</div>
</div>
</div>
</div>
<!-- fine dei modal per gestire le azioni del gestionale -->
<!-- IMPORTANTE: AGGIUNGERE IL CSRF TOKEN PRIMA DI ANDARE IN PRODUZIONE -->
#endsection
For table-pratiche i've this structure of my livewire component
table-pratiche:
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Pratiche</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example4" class="display" style="min-width: 845px">
<thead>
<tr>
<th>Soggetto</th>
<th>Codice Fiscale</th>
<th>Indirizzo</th>
<th>Tipo di imposta</th>
<th>Carico</th>
<th>Riscosso</th>
<th>Sgravio</th>
<th>Residuo</th>
<th>Assegnatario</th>
<th>Data assegn.</th>
<th>Dettagli</th>
</tr>
</thead>
<livewire:table-pratiche-content />
<livewire:tbl-pratiche-footer-filter />
</table>
</div>
</div>
</div>
</div>
</div>
table-pratiche-content:
<tbody id="filter_result">
#if (!empty($pratiche))
<?php
$carico = 0;
$riscosso = 0;
$sgravio = 0;
$residuo = 0;
?>
#foreach ($pratiche['data'] as $p)
<tr wire:click="clickPartiteTrigger({{ $p['id_minuta'] }})">
<td>{{ $p['denominazioneSoggetto'] }}</td>
<td>{{ $p['codiceFiscale'] }}</td>
<td>{{ $p['indirizzoPOSTA'] }}</td>
<td>{{ $p['descrizione_sintetica'] }}</td>
<td>{{ $p['carico'] }}</td>
<td>{{ $p['riscosso'] }}</td>
<td>{{ $p['sgravio'] }}</td>
<td>{{ $p['residuo'] }}</td>
<td>Collaboratore</td>
<td>{{ $p['data_assegnazione'] }}</td>
<td><span class="badge light badge-warning">Pending</span></td>
<?php
$carico = $carico + $p['carico'];
$riscosso = $riscosso + $p['riscosso'];
$sgravio = $sgravio + $p['sgravio'];
$residuo = $residuo + $p['residuo'];
?>
</tr>
#endforeach
#endif
</tbody>
For table-partite in the same way i've:
table-partite:
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Partite</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example5" class="display" style="min-width: 845px">
<thead>
<tr>
<th>Anno ruolo</th>
<th>Numero ruolo</th>
<th>Agente Riscossione</th>
<th>Anno imposta</th>
<th>Tipo imposta</th>
<th>Partita</th>
<th>Carico</th>
<th>Riscosso</th>
<th>Sgravio</th>
<th>Residuo</th>
<th>Peocedura</th>
<th>Inesigibile</th>
<th>Stato</th>
</tr>
</thead>
<livewire:table-partite-content />
<livewire:tbl-partite-footer-filter />
</table>
</div>
</div>
</div>
</div>
</div>
table-partite-content
<tbody id="partite_result">
#if (!empty($partite))
#foreach ($partite['data'] as $pt)
<tr wire:click="clickArticoliTrigger({{ $pt['id']}})">
<td>{{ $pt['annoRuolo'] }}</td>
<td>{{ $pt['numeroRuolo'] }}</td>
<td>{{ $pt['agenteRiscossione'] ?? ''}}</td>
<td>{{ $pt['annoRif'] ?? '' }}</td>
<td>{{ $pt['tipoImposta'] ?? '' }}</td>
<td>{{ $pt['id_minuta_partita'] ?? '' }}</td>
<td>{{ $pt['importoCarico'] }}</td>
<td>{{ $pt['pagatoNormale'] }}</td>
<td>{{ $pt['pagatoDiscarico'] }}</td>
<td>{{ $pt['importoResiduo'] }}</td>
<td>{{ $pt['proceduraEsecutiva'] }}</td>
<td>{{ $pt['importoInesigibilita'] }}</td>
<td>{{ $pt['stato'] ?? ''}}</td>
</tr>
#endforeach
#endif
</tbody>
and in the last, for table-articoli i've
table-articoli
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Articoli</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example4" class="display" style="min-width: 845px">
<thead>
<tr>
<th>Codice Tributo</th>
<th>Descrizione</th>
<th>Progressivo</th>
<th>Carico</th>
<th>Dettaglio utenza</th>
</tr>
</thead>
<livewire:table-articoli-content />
</table>
</div>
</div>
</div>
</div>
</div>
-table-articoli-content
<tbody id="articoli_result">
#if (!empty($articoli))
#foreach ($articoli as $a)
<tr>
<td>{{ $a->codiceEntrata }}</td>
<td>{{ $a->descrizioneArticolo }}</td>
<td>{{ $a->progressivoArticolo}}</td>
<td>{{ $a->importoCarico }}</td>
<td>{{ $a->descrizioneArticolo}}</td>
</tr>
#endforeach
#endif
</tbody>
The livewire components are the component posted in the previous question

base table or view not found?

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

How to create login history in database while login using email and password?

I want to create a login history when user login to my site.login history should be saved in the table login_history.
Migration code is given below:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class LoginHistory extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('login_history', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('ip')->default(false);
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('login_history');
}
}
User login is given below:
#extends('site')
{{-- Web site Title --}}
#section('title') {{{ trans('site/user.login') }}} :: #parent #stop
{{-- Content --}}
#section('content')
<article>
<div class="container">
<div id="loginbox" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">Login</div>
<div style="float:right; font-size: 80%; position: relative; top:-20px">
<a target="blank" href="{{ url('password/email')}}">
Forgot password?
</a>
</div>
</div>
<div style="padding-top:30px" class="panel-body" >
<div style="display:none" id="login-alert" class="alert alert-danger col-sm-12">
</div>
#include('errors.list')
<form class="form-horizontal" role="form" method="POST" action="{{ URL::to('/user/login') }}" autocomplete="off">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-user"></i>
</span>
<input type="email" class="form-control" required placeholder="enter your login email" name="email" value="{{ old('email') }}">
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-lock"></i>
</span>
<input type="password" required placeholder="enter your login password" class="form-control" name="password">
</div>
<div class="input-group">
<div class="checkbox">
<label>
<input id="login-remember" type="checkbox" name="remember" value="1">
Remember me
</label>
</div>
</div>
<div style="margin-top:10px" class="form-group">
<div class="col-sm-12 controls">
<button type="submit" class="btn btn-default" >
Login
</button>
<!-- <a id="btn-fblogin" href="#" class="btn btn-primary">Login with Facebook</a> -->
</div>
</div>
<div class="form-group">
<div class="col-md-12 control">
<div style="border-top: 1px solid #ccc; padding-top:15px; font-size:85%" >
Don't have an account!
Create an account
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</article>
#endsection
I think the best way would be to extend the Auth ServiceProvider like here: https://laravel.com/docs/5.0/extending#authentication
And inside the check function, insert a new login_history row.

Categories