Update loop records via Laravel and livewire - php

Hi, I would like some help on this.
This loop comes from my products table, using pure laravel I load each product in inputs, so if I make any changes and click on an update button it is redirected to a route to update the changed product.
How could I do this same idea using livewire?
How to display the updated data in this loop without having to go to another route.
My blade:
#forelse($categoryProduct->products as $key => $product)
<li>
<div class="mt-3 card">
<div class="card-body">
<div class="row">
<div class="col-1">
<x-inputs.group class="">
<div
x-data="imageViewer('{{ $product->img ? \Storage::url($product->img) : '' }}')">
<x-inputs.partials.label name="img" label="Foto">
</x-inputs.partials.label><br />
<!-- Show the image -->
<template x-if="imageUrl">
<img :src="imageUrl"
class="object-cover border border-gray-200 rounded"
style="width: 100px; height: 100px;" />
</template>
<!-- Show the gray box when image is not available -->
<template x-if="!imageUrl">
<div class="bg-gray-100 border border-gray-200 rounded"
style="width: 140px; height: 140px;"></div>
</template>
<div class="mt-2">
<input wire:model="img" type="file" name="img" id="img"
#change="fileChosen" />
</div>
#error('img')
#include('components.inputs.partials.error')
#enderror
</div>
</x-inputs.group>
</div>
<div class="col-11">
<div class="row">
<div class="col-10">
<input type="text" class="form-control" placeholder="Name"
value="{{ $product->name }}">
</div>
<div class="col-2">
<button
onclick="confirm('Tem certeza que deseja deletar esse produto?') || event.stopImmediatePropagation()"
wire:click.prevent="deleteProduct({{ $product->id }})"
class="btn btn-user btn-danger">
×
</button>
</div>
<div class="mt-3 col-10">
<textarea class="form-control"
placeholder="Description">{{ $product->description }}</textarea>
</div>
<div class="mt-3 col-2">
<input type="number" class="form-control"
placeholder="Price" value="{{ $product->price }}">
</div>
</div>
</div>
</div>
</div>
</li>
#empty
This is the way I'm feeding the loop:
public function render()
{
$this->shop = Shop::with([
'categoryProducts',
'categoryProducts.products',
'districts'
])->where('user_id', Auth::user()->id)->first();
return view('app.menu-controller')
->extends('layouts.app')
->section('content');
}

You can create a Livewire ProductComponent and in blade have the div card once this loop the same elements
https://www.laravel-livewire.com/docs/2.x/making-components
https://www.laravel-livewire.com/docs/2.x/rendering-components
<div>
<div class="mt-3 card">
<div class="card-body">
<div class="row">
<div class="col-1">
<x-inputs.group class="">
<div
x-data="imageViewer('{{ $product->img ? \Storage::url($product->img) : '' }}')">
<x-inputs.partials.label name="img" label="Foto">
</x-inputs.partials.label><br />
//......................
</div>
</div>
Use model binding in nested component for the loop
https://www.laravel-livewire.com/docs/2.x/nesting-components
#forelse($categoryProduct->products as $key => $product)
<li>
#livewire('product-component',['product' => $product], key($user->id))
</li>
and in component
public Product $product;
public function render()
{
return view('livewire.product-component')
->extends('layouts.app')
->section('content');
}
The rest in in Livewire documentation, when you get on there could come here with issues or questions. Greetings

Related

Table disappears after clicking on add button on Livewire

My Livewire Component
public $productId;
public $allTariff = [];
public $rowProducts = [];
public function mount()
{
$this->rowProducts = Products::all();
$this->allTariff = [
['productId' => '', 'basicCharge' => '', 'additionalCharge' => '']
];
}
public function addProduct()
{
$this->allTariff[] = ['productId' => '', 'basicCharge' => '', 'additionalCharge' => ''];
}
public function render()
{
$rowProducts = Products::all();
return view('livewire.admin.admin-add-tariffs-component', ['rowProducts'=>$rowProducts)->layout('layouts.admin.base');
}
My View File
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name" wire:model="tariffName" >
</div>
</div><hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr>
<td>
<select name="allTariff[{{$index}}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user" name="allTariff[{{$index}}][basicCharge]" placeholder="Basic Charge" wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user" name="allTariff[{{$index}}][additionalCharge]" placeholder="Weight Charge" wire:model="allTariff.{{ $index }}.additionalCharge" required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary"
wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
Every time I click on the add tariff button this photo it give the blank page on this photo, but on console an html response is given.
I have tried a couple methods and tricks still no way out, just stuck for days
I have already include the livewire #livewireStyles and #livewireScripts, and i can't find an answer anywhere else cause i don't see any question that match my problem, and i'm kinda new to livewire
When using Livewire, there are a few things you need to be aware of. Due to the nature of how Livewire updates the page, there are some structural rules you need to follow.
The first and probably most important thing here, is that every Livewire-component view should only consist of one root element. And this includes comments!
If we count the root elements in your view, there are three - a comment, a div, and then another comment. So the first thing I did here, was to move the comments inside that div.
<div class="container-fluid">
<!-- Begin Page Content -->
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name"
wire:model="tariffName">
</div>
</div>
<hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr>
<td>
<select name="allTariff[{{ $index }}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][basicCharge]"
placeholder="Basic Charge"
wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][additionalCharge]"
placeholder="Weight Charge"
wire:model="allTariff.{{ $index }}.additionalCharge"
required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary" wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
Then another thing I would recommend that you look into is using wire:key on the tr element inside your table-loop, and on the option element inside your inner loop. The value to wire:key should always be unique to that particular row, so using $loop->index is not generally advised. You can generate a dummy-ID for each record that you add to your array, which sole purpose is to track the individual row. Here's how, see the wire:key I added in the template,
<div class="container-fluid">
<!-- Begin Page Content -->
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name"
wire:model="tariffName">
</div>
</div>
<hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr wire:key="tariff-{{ $value->wireKey }}">
<td>
<select name="allTariff[{{ $index }}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}" wire:key="product-{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][basicCharge]"
placeholder="Basic Charge"
wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][additionalCharge]"
placeholder="Weight Charge"
wire:model="allTariff.{{ $index }}.additionalCharge"
required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary" wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
And then in your component, just generate a unique string
class AdminAddTariffsComponent
{
public $productId;
public $allTariff = [];
public $rowProducts = [];
public function mount()
{
$this->rowProducts = Products::all();
$this->addProduct();
}
public function addProduct()
{
$this->allTariff[] = [
'productId' => '',
'basicCharge' => '',
'additionalCharge' => '',
'wireKey' => \Str::uuid(),
];
}
public function render()
{
return view('livewire.admin.admin-add-tariffs-component')
->layout('layouts.admin.base');
}
}

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>

I'm handling Client site from admin panel

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

how to get URL value in laravel?

So, i tried laravel and i got stuck when i want to get URL value as a value for my database. Here is the code in my controller.
public function store(Request $request, $shoe_id)
{
//Insert Data
$cart = new Cart;
$cart->user_id = Auth::user()->id;
$cart->shoe_id = $shoe_id;
$cart->quantity = $request->quan;
$cart->save();
return redirect()->back();
}
and here is the problem i've encountered:
it says that the {shoe_id} is string where i wanted to be an integer from the URL
Here what my website looks like:
My blade
Here is my web.php:
Route::get('/','homeController#main')->name('home');
Route::get('/home','homeController#main')->name('home');
Route::get('/detail/{shoe_id}', 'homeController#detail');
Route::get('/cart/{shoe_id}','CartController#show');
Route::post('/cart/{shoe_id}','CartController#store');
Here is my blade:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div style="text-align:center;">
<img src="{{ asset("$cart->shoe_image") }}" alt="" style=" width:350px; height:350px;">
<div class="card-header">{{$cart->shoe_name}}</div>
<div class="card-header">${{$cart->shoe_price}}</div>
<div class="card-header">{{$cart->shoe_description}}</div>
</div>
<div class="card-header form-group">
<form method="POST" action="/cart/{shoe_id}" enctype="multipart/form-data">
#csrf
<div class="form-row">
<div class="col-md-2">
<label for="quantity">Quantity:</label>
</div>
<div>
<input class = "form-control" type="text" id="quantity" name="quan"><br><br>
</div>
<button class="btn btn-primary" type="submit" name="addcart">Add to Cart</button>
</div>
</form>
{{-- <a class="btn btn-primary" href="#">Add to Cart</a> --}}
</div>
</div>
</div>
</div>
</div>
#endsection
what i want to do: input the inputted data to database. My database has table called cart with attribute of id, user_id, shoe_id.
In your form action you should provide the actual value for the shoe_id then it will work as expected. action="/cart/{{ $cart->shoe_id }}"
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div style="text-align:center;">
<img src="{{ asset("$cart->shoe_image") }}" alt="" style=" width:350px; height:350px;">
<div class="card-header">{{$cart->shoe_name}}</div>
<div class="card-header">${{$cart->shoe_price}}</div>
<div class="card-header">{{$cart->shoe_description}}</div>
</div>
<div class="card-header form-group">
<form method="POST" action="/cart/{{ $cart->shoe_id }}" enctype="multipart/form-data">
#csrf
<div class="form-row">
<div class="col-md-2">
<label for="quantity">Quantity:</label>
</div>
<div>
<input class = "form-control" type="text" id="quantity" name="quan"><br><br>
</div>
<button class="btn btn-primary" type="submit" name="addcart">Add to Cart</button>
</div>
</form>
{{-- <a class="btn btn-primary" href="#">Add to Cart</a> --}}
</div>
</div>
</div>
</div>
</div>
#endsection

My Php Script Exception message: count(): Parameter must be an array or an object that implements Countable

"count(): Parameter must be an array or an object that implements
Countable (View:
D:\xampp\htdocs\btrade\core\resources\views\dashboard\user-details.blade.php)"
Looking for I saw that some have this error in their code, but I did not find how can i solve my problem please help me
i think This is the failing case:
#if(count($user))
My php version : PHP 7.2.0
this my error imge
this is my code
#extends('layouts.dashboard')
#section('style')
<link href="{{ asset('assets/admin/css/bootstrap-toggle.min.css') }}" rel="stylesheet">
#endsection
#section('content')
#if(count($user))
<div class="row">
<div class="col-md-12">
<div class="portlet blue box">
<div class="portlet-title">
<div class="caption font-dark">
<strong>User Details</strong>
</div>
<div class="tools"> </div>
</div>
<div class="portlet-body" style="overflow:hidden;">
<div class="col-md-3">
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption uppercase bold">
<i class="fa fa-user"></i> PROFILE </div>
</div>
<div class="portlet-body text-center" style="overflow:hidden;">
<img src="#if($user->image == 'user-default.png') {{ asset('assets/images/user-default.png') }} #else {{ asset('assets/images') }}/{{ $user->image }}#endif" class="img-responsive propic" alt="Profile Pic">
<hr><h4 class="bold">User Name : {{ $user->username}}</h4>
<h4 class="bold">Name : {{ $user->name }}</h4>
<h4 class="bold">BALANCE : {{ $user->balance }} {{ $basic->currency }}</h4>
<hr>
#if($user->login_time != null)
<p>
<strong>Last Login : {{ \Carbon\Carbon::parse($user->login_time)->diffForHumans() }}</strong> <br>
</p>
<hr>
#endif
#if($last_login != null)
<p>
<strong>Last Login From</strong> <br> {{ $last_login->user_ip }} - {{ $last_login->location }} <br> Using {{ $last_login->details }} <br>
</p>
#endif
</div>
</div>
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-12">
<div class="portlet box purple">
<div class="portlet-title">
<div class="caption uppercase bold">
<i class="fa fa-desktop"></i> Details </div>
<div class="tools"> </div>
</div>
<div class="portlet-body">
<div class="row">
<!-- START -->
<a href="{{ route('user-repeat-all',$user->username) }}">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" style="margin-bottom: 20px;">
<div class="dashboard-stat blue">
<div class="visual">
<i class="fa fa-recycle"></i>
</div>
<div class="details">
<div class="number">
<span data-counter="counterup" data-value="{{ $total_repeat }}">0</span>
</div>
<div class="desc uppercase bold"> REPEAT </div>
</div>
<div class="more">
<div class="desc uppercase bold text-center">
{{ $basic->symbol }}
<span data-counter="counterup" data-value="{{ $total_repeat_amount }}">0</span> REPEAT
</div>
</div>
</div>
</div>
</a>
<!-- END -->
<a href="{{ route('user-deposit-all',$user->username) }}">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" style="margin-bottom: 20px;">
<div class="dashboard-stat green">
<div class="visual">
<i class="fa fa-cloud-download"></i>
</div>
<div class="details">
<div class="number">
<span data-counter="counterup" data-value="{{ $total_deposit }}">0</span>
</div>
<div class="desc uppercase bold "> DEPOSIT </div>
</div>
<div class="more">
<div class="desc uppercase bold text-center">
{{ $basic->symbol }}
<span data-counter="counterup" data-value="{{ $total_deposit_amount }}">0</span> DEPOSIT
</div>
</div>
</div>
</div>
</a>
<!-- END -->
<a href="{{ route('user-withdraw-all',$user->username) }}">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" style="margin-bottom: 20px;">
<div class="dashboard-stat red">
<div class="visual">
<i class="fa fa-cloud-upload"></i>
</div>
<div class="details">
<div class="number">
<span data-counter="counterup" data-value="{{ $total_withdraw }}">0</span>
</div>
<div class="desc uppercase bold "> WITHDRAW </div>
</div>
<div class="more">
<div class="desc uppercase bold text-center">
{{ $basic->symbol }}
<span data-counter="counterup" data-value="{{ $total_withdraw_amount }}">0</span> WITHDRAW
</div>
</div>
</div>
</div>
</a>
<!-- END -->
<a href="{{ route('user-login-all',$user->username) }}">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" style="margin-bottom: 20px;">
<div class="dashboard-stat yellow">
<div class="visual">
<i class="fa fa-sign-in"></i>
</div>
<div class="details">
<div class="number">
<span data-counter="counterup" data-value="{{ $total_login }}">0</span>
</div>
<div class="desc uppercase bold "> Log In </div>
</div>
<div class="more">
<div class="desc uppercase bold text-center">
VIEW DETAILS
</div>
</div>
</div>
</div>
</a>
<!-- END -->
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="portlet box blue-ebonyclay">
<div class="portlet-title">
<div class="caption uppercase bold">
<i class="fa fa-cogs"></i> Operations </div>
</div>
<div class="portlet-body">
<div class="row">
<div class="col-md-6 uppercase">
<i class="fa fa-money"></i> add / substruct balance
</div>
<div class="col-md-6 uppercase">
<i class="fa fa-envelope-open"></i> Send Email
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="portlet box green">
<div class="portlet-title">
<div class="caption uppercase bold">
<i class="fa fa-cog"></i> Update Profile </div>
</div>
<div class="portlet-body">
<form action="{{ route('user-details-update') }}" method="post">
{!! csrf_field() !!}
<input type="hidden" name="user_id" value="{{ $user->id }}">
<div class="row uppercase">
<div class="col-md-4">
<div class="form-group">
<label class="col-md-12"><strong>Name</strong></label>
<div class="col-md-12">
<input class="form-control input-lg" name="name" value="{{ $user->name }}" type="text">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-12"><strong>Email</strong></label>
<div class="col-md-12">
<input class="form-control input-lg" name="email" value="{{ $user->email }}" type="text">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-12"><strong>Phone</strong></label>
<div class="col-md-12">
<input class="form-control input-lg" name="phone" value="{{ $user->phone }}" type="text">
</div>
</div>
</div>
</div><!-- row -->
<br><br>
<div class="row uppercase">
<div class="col-md-4">
<div class="form-group">
<label class="col-md-12"><strong>STATUS</strong></label>
<div class="col-md-12">
<input data-toggle="toggle" {{ $user->status == 0 ? 'checked' : ''}} data-onstyle="success" data-size="large" data-offstyle="danger" data-on="Active" data-off="Blocked" data-width="100%" type="checkbox" name="status">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-12"><strong>EMAIL VERIFICATION</strong></label>
<div class="col-md-12">
<input data-toggle="toggle" {{ $user->email_verify == 1 ? 'checked' : ''}} data-onstyle="success" data-size="large" data-offstyle="danger" data-on="Verified" data-off="Not Verified" data-width="100%" type="checkbox" name="email_verify">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-12"><strong>PHONE VERIFICATION</strong></label>
<div class="col-md-12">
<input data-toggle="toggle" {{ $user->phone_verify == 1 ? 'checked' : ''}} data-onstyle="success" data-size="large" data-offstyle="danger" data-on="Verified" data-off="Not Verified" data-width="100%" type="checkbox" name="phone_verify">
</div>
</div>
</div>
</div><!-- row -->
<br><br>
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn blue btn-block btn-lg">UPDATE</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div><!-- col-9 -->
</div>
</div>
</div>
</div><!-- ROW-->
#else
<div class="text-center">
<h3>No User Found</h3>
</div>
#endif
#endsection
#section('scripts')
<script src="{{ asset('assets/admin/js/bootstrap-toggle.min.js') }}"></script>
<script src="{{ asset('assets/admin/js/jquery.waypoints.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/admin/js/jquery.counterup.min.js') }}" type="text/javascript"></script>
#endsection
The $user variable isn't an array. If that variable must not be an array remove the count function from if statement.
In php5, php7.0, php7.1 it works, but in php7.2 does not work.
#if($user)...
for laravel use below code in web.php
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
// Ignores notices and reports all other kinds... and warnings
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
// error_reporting(E_ALL ^ E_WARNING); // Maybe this is enough
}
PHP had changed function count() in version 7.2.
In PHP 7.3 will add is_countable();
You can add this function:
function is_countable($var) {
return (is_array($var) || $var instanceof Countable);
}
if (is_countable($user) && count($user)) {
//
}
and remove it in PHP 7.3

Categories