I made a delete multiple function, but I have some troubles with. When I select 2 checkboxes, and submit it but after that I'm redirected to url/article/delete/559 with null message at dd($article_id).
Here is my controller function:
public function deleteArticles (requ $request){
$article_id = $request['news_id'];
dd($article_id);
DB::table('contacts')
->whereIn('id', $article_id)
->delete();
return back();
}
public function delete($id)
{
$careerSolution = \App\Contact::find($id);
$careerSolution->delete();
return redirect(URL::previous());
}
Here is my routes
Route::get('article/delete/{id?}', 'ContactController#delete');
Route::post('noticeboard/{page?}', array('as' => 'noticeboard', 'uses' => 'ContactController#deleteArticles'));
Here is my view
<div id="my_contacts_grid" class="profile-edit tab-pane fade in active" style="background: none repeat scroll 0 0;">
<dl class="dl-horizontal">
<?php $count_user = 0; ?>
#foreach($users as $user)
#if($count_user == 0)
<div class="row margin-bottom-20">
#endif
<?php $count_user++; ?>
<form method="POST" action="{{ action ('ContactController#deleteArticles')}}">
{{csrf_field()}}
<div class="col-sm-6 sm-margin-bottom-20">
<div class="profile-blog" style="padding: 0px">
<img class=" noticeboard-profile-picture" src="{{ asset('thumbnail') }}/{{ $user->profile_picture }}" alt="" style="margin-left: 20px;margin-top: 15px;">
<div style="top: 35px;position: relative;right: 85px;margin-bottom:30px" class="name-location">
<ul class="list-unstyled col-xs-12" >
<li>
<strong style="display: inline-table !important">
<h3>#if($user->role[0]->slug == "individuals")
<i style="font-size: 13px;left: 60px;position: relative;top: 2px;" class="icon-user"></i>
#elseif($user->role[0]->slug =='organizations')
<i style="font-size: 13px;left: 60px;position: relative;top: 2px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
#endif<a style="font-size: 16px;left: 60px;position: relative;top: 2px" href="{{ url('') }}/{{ $user->username }}"> {{ $user->username }}</a></h3></strong>
<p style="right: 10px;position: relative;width: 110%">
<i style="padding: 5px" class="icon-real-estate-020 u-line-icon-pro"></i><strong style="display: inline-table !important;font-size: 13px">Location : </strong> {{ $user->country->country }} <span class="{{$user->country->flag}}"></span><br>
<i style="padding: 5px" class="icon-notebook fa-"></i><strong style="display: inline-table !important;font-size: 13px">Industry : </strong> {{ $user->industry->industry }}<br>
#if($user->role[0]->slug == "individuals")
#foreach($user->career_path as $career_path)
<i style="padding: 5px" class="icon-speedometer"></i><strong style="display: inline-table !important;font-size: 13px">Function : </strong> {{ $career_path->functions->function }}
#break;
#endforeach
#elseif($user->role[0]->slug =='organizations')
<i style="padding: 5px" class="icon-frame fa-"></i><strong style="display: inline-table !important;font-size: 13px">Organization : </strong> {{ $user->organization_type->organization_type }}<br>
#endif
</p>
</li>
</ul>
</div>
<hr>
<ul class="social-icons social-icons-color" style="display:none;">
<div class="social-cu" id="social-cu">
<li class="facebook_share" link="{{ url('') }}/{{ $user->username }}" style="left: 5px;position: relative">
<img id="social-im" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/facebook-test.png') }}" alt="" style="height: 22px !important">
</li>
<li class="twitter_share" link="{{ url('') }}/{{ $user->username }}" name="{{ $user->username }} Workstickers Profile" style="left: 15px; position: relative">
<img id="social-im" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/twitter-test.png') }}" alt="" style="height: 22px !important">
</li>
<li class="whatapp_share" link="{{ url('') }}/{{ $user->username }}" name="{{ $user->username }} Workstickers Profile" style="left: 25px;position: relative">
<a href="whatsapp://send?text={{ url('') }}/{{ $user->username }}" style="top: 5px; position: relative">
<img id="social-w" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/Whatsapp.png') }}" style="height: 25px !important" alt="">
</a>
</li>
</div>
</ul>
<ul class="list-inline share-list" style="text-align: center;padding-bottom:10px">
<li>
<input name="news_id[]" type="checkbox" class="checkbox_news" value="{{$user->id}}"/>
</li>
<li>
<i class="fa fa-times"></i> Remove
</li>
<li class="send-contact-message " data-toggle="modal" data-target="#ssend_message_touser_{{ $user->id }}">
<i class="fa fa-paper-plane"></i>Send message
</li>
<li class="share-link">
<i class="fa fa-share-alt"></i> Share
</li>
</ul>
{!! Form::close() !!}
</div>
</div>
#if($count_user == 2)
</div>
<?php $count_user = 0; ?>
#endif
<!-- Modal -->
<div class="modal fade" id="ssend_message_touser_{{ $user->id }}" role="dialog" style="margin-top:40px;">
<div class="modal-dialog">
<!-- Modal email-->
<div class="modal-content" style="border-radius: 0px;top: 200px">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="mt-5">Send message to {{ $user->username }}</h4>
</div>
<div class="modal-body">
{!! Form::open(['class' => 'form-horizontal sky-form sky-changes-3','url' => 'message-send']) !!}
<div class="form-group" >
<label class="col-lg-2 control-label" style="display: none">To</label>
<div class="col-lg-10">
<input style="display: none" class="form-control" type="email" name="username" value="{{ $user->username }}" readonly>
<input class="form-control" type="hidden" name="contact_user_id" value="{{ $user->id }}">
<input class="form-control" type="hidden" name="url" value="{{ url('') }}/{{ $user->username }}">
</div>
</div>
<fieldset>
<section>
<label class="label">Subject</label>
<label class="input">
<i class="icon-append fa fa-tag"></i>
<input type="text" name="subject" id="subject">
</label>
</section>
<section>
<label class="label">Message</label>
<label class="textarea">
<i class="icon-append fa fa-comment"></i>
<textarea rows="4" name="message" id="message" ></textarea>
</label>
</section>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" style="bottom: 2px;position: relative">Close</button>
<button type="submit" class="btn-u btn-u-primary">Send message</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
<!-- end email Modal -->
#endforeach
<a href="{{ url('article/delete/'.$user->id) }}" role="button" class="btn btn-xs btn-danger" onclick="return confirm('Are you sure you want to delete this article?');">
<i class="fa fa-trash"></i>
</a>
</form>
{!! $users->render() !!}
</dl>
</div>
<style>
#social-cu{
width: 120px !important;
left: 200px;
top: -25px !important;
}
#social-im{
float: left;
width: 22px;
margin-right: 0px;
}
#social-w{
float: left;
width: 25px;
margin-right: 0px;
position: relative;
bottom: 3px;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function() {
App.initScrollBar();
RegForm.initRegForm();
Datepicker.initDatepicker();
CheckoutForm.initCheckoutForm();
StyleSwitcher.initStyleSwitcher();
$(".send-contact-message").live('click', function(){
var user_id = $(this).attr('data-user-id');
$('#ssend_message_touser_'+user_id).modal('show');
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
// StyleSwitcher.initStyleSwitcher();
$("#select_all").click(function () {
$(".checkbox_news").prop('checked',true);
});
$("#deselect_all").click(function () {
$(".checkbox_news").prop('checked',false);
});
});
</script>
So, when I check a checkbox or multiple, I should be able to have a multiple delete.
$careerSolution = \App\Contact::find($id);
When it's return null then you get error Call to a member function delete().
Use this One:
\App\Contact::where('id', $id)->delete();
Related
I am using laravel framework to develop web application i have one simple form i have one table which is coming from API based on that i am loading all the values into the table everything works fine but when i click on remove button it's taking first record id (i.e.. first item id of the array for all items )only instead of taking that particular record id,could you please help me where did i mistake..?
#include('header')
<!DOCTYPE html>
<html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.12.9/dist/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.left-btn {
float: left;
}
.right-btn {
float: right;
}
.table-bordered {
margin-top: 3%;
}
#new-form {
border: 3px solid black;
width: 600px;
display: flex;
align-items: center;
justify-content: center;
}
table {
font-family: "Times New Roman";
font-size: 20px;
}
span.circle {
background: #ADD8E6;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
color: #6e6e6e;
display: inline-block;
font-weight: bold;
line-height: 40px;
margin-right: 5px;
text-align: center;
width: 40px;
}
.buttons {
width: 200px;
margin: 0 auto;
display: inline;
}
.action_btn {
width: 200px;
margin: 0 auto;
display: inline;
}
.confirm_buttons {
width: 60px;
}
.popup {
font-size: 15px;
}
.file:focus,
.file:active {
box-shadow: none !important;
-moz-box-shadow: none !important;
-webkit-box-shadow: none !important;
outline: none !important;
}
.glyphicon-remove {
font-size: 20px;;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-6">
<h4 class="" style="font-size:20px;font-weight:80px;">User Records</h4>
</div>
<div class="col-6 text-right">
<button type="button" style="font-size:20px;font-weight:28px;" class="btn btn-primary"
data-toggle="modal" data-target="#exampleModal">
Add New Employee
</button>
</div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h5 class="modal-title" id="exampleModalLabel">Add New Employee</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body popup">
<form action="<?php echo url('postemployee'); ?>" method="POST" enctype="multipart/form-data">
#csrf
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<div class="modal-body">
<div class="form-group">
<label for="email1">Email</label>
<input type="email" class="form-control" id="email"
aria-describedby="emailHelp" name="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="email1">Full Name</label>
<input type="text" class="form-control" id="fname"
aria-describedby="emailHelp" name="fname" placeholder="Enter Name">
</div>
<div class="form-group">
<label for="email1">Date Of Joining</label>
<input type="date" class="form-control" name="doj" id="doj"
aria-describedby="emailHelp">
</div>
<div class="form-group">
<label for="password1">Date Of Leaving</label>
<input type="date" class="form-control" id="password1" name="dol">
</div>
<div class="form-check form-inline">
<label class="form-check-label" for="defaultCheck1">
Still working
</label>
<input class="form-check-input" type="checkbox" name="current_date"
id="defaultCheck1">
</div>
<div class="form-group form-inline">
<label for="email1">Upload Image</label>
<input type="file" class="file" class="form-control" id="email"
name="image" aria-describedby="emailHelp">
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</form>
</form>
</div>
</div>
</div>
</div>
<table class="table table-bordered" id="table">
<tr>
<th>Avatar</th>
<th>Name</th>
<th>Email</th>
<th>Experience</th>
<th>Action</th>
</tr>
#foreach ($employees as $employee)
<tr>
<td>
#if (isset($employee['image_path']))
<img style="border-radius: 50%;height:40px;width:40px;"
src={{ URL::asset("/images/{$employee['image_path']}") }} alt="Avatar">
#else
<span class="circle">{{ ucfirst(mb_substr($employee['name'], 0, 1)) }}</span>
#endif
</td>
<td>{{ ucfirst($employee['name']) }}</td>
<td>{{ $employee['email'] }}</td>
<td>
#if ($employee['joining_date'] == '0 Days')
<span data-toggle="tooltip" data-placement="top" title="Fresher"
style="color:green;font-weight:500;">Joined Today</span>
#else
{{ $employee['joining_date'] }}
#endif
</td>
<td>
<button type="submit" class="btn" data-toggle="modal" data-target="#exampleModalCenter"
value="{{ $employee['id'] }}">
<span style="margin-top:10px;" onclick="getId()" id="mt"
class="glyphicon glyphicon-remove"><span>Remove</span>
</span>
</button>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog"
aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body text-center">
Are you sure you want to delete ?
<br><br>
<form action="<?php echo url('delete'); ?>" method="POST">
#csrf
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-primary confirm_buttons"
data-toggle="modal" name="delete_id" value="{{ $employee['id'] }}"
data-target="#exampleModalCenter">Yes</button>
<button type="submit" class="btn btn-secondary confirm_buttons"
data-toggle="modal" data-target="#exampleModalCenter">No</button>
</form>
</div>
</div>
</div>
</div>
</td>
</tr>
#endforeach
</table>
</div>
<div class="right-btn">
</div>
<script type="text/javascript">
</script>
</body>
</html>
you can use onclick functionality for passing value ,try the following approach it will work
<button type="submit" class="btn" data-toggle="modal" data-target="#exampleModalCenter" data-backdrop="static" data-keyboard="false" value="{{ $employee['id'] }}" onclick="id(this.value)">
<span style="margin-top:10px;" id="rmr" class="glyphicon glyphicon-remove"><span>Remove</span>
</span>
</button>
<!--refactor the following line in modal target -->
<button type="submit" class="btn btn-primary confirm_buttons" data-toggle="modal" name="delete_id" id="del_id" data-target="#exampleModalCenter">Yes</button>
<script type="text/javascrpt">
function id(objButton) {
document.getElementById('del_id').value = objButton;
}
</script>
I have a bug when I want to write a thread. I write 2 letters after he stops writing I have to click again to continue writing.
Threadmodel
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Qirolab\Laravel\Reactions\Traits\Reactable;
use Qirolab\Laravel\Reactions\Contracts\ReactableInterface;
class Thread extends Model implements ReactableInterface
{
use HasFactory, Reactable;
public function user(){
return $this->belongsTo(User::class);
}
public function replies(){
return $this->hasMany(ThreadReply::class);
}
public function isLiked()
{
if (auth()->user()) {
return $this->isReactBy(auth()->user());
}
return false;
}
public function removeLike()
{
if (auth()->user()) {
return $this->removeReaction();
}
return false;
}
}
ThreadController
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Models\Thread;
use App\Models\ThreadReply;
use App\Models\SubCategory;
use Auth;
class ThreadController extends Controller
{
public function create($subcategory){
return view('threads.create',compact('subcategory'));
}
public function store(Request $request,$subcategory){
$category = SubCategory::where('title',$subcategory)->first();
$thread = new Thread();
$thread->title = $request->title;
$thread->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->title)).'-'.Str::random(5);
$thread->description = $request->description;
$thread->sub_category_id = $category->id;
$thread->user_id = Auth::user()->id;
$thread->save();
return redirect()->route('subcategory.thread',$request->subcategory);
}
public function show($slug){
$thread = Thread::where('slug',$slug)->first();
return view('threads.show',compact('thread'));
}
}
App/HTTP/Livewire/ThreadDisplay.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Thread;
use App\Models\User;
use App\Models\ThreadReply;
use Auth;
class ThreadDisplay extends Component
{
public Thread $thread;
public ThreadReply $threadreply;
public $description;
protected $listeners = ['update-thread' => 'updatethread'];
public function mount(Thread $thread)
{
$this->thread = $thread;
// dd($this->thread);
}
public function react($reaction)
{
if ($this->thread->isLiked()) {
$this->thread->toggleReaction($reaction);
if($reaction == $this->thread->reacted()?->type){
if($reaction == 'hand-thumbs-down-fill' || $reaction == 'emoji-frown-fill' ){
$user = User::find($this->thread->user->id)->increment('reactions', 1);
}else{
$user = User::find($this->thread->user->id)->decrement('reactions', 1);
}
}else{
$negative = ['hand-thumbs-down-fill','emoji-frown-fill'];
$positive = ['hand-thumbs-up-fill','emoji-heart-eyes-fill','heart-fil'];
if(in_array($reaction,$negative)){
if(!in_array($this->thread->reacted()->type,$negative)){
$user = User::find($this->thread->user->id)->decrement('reactions', 2);
}
}else{
if(!in_array($this->thread->reacted()->type,$positive)){
$user = User::find($this->thread->user->id)->increment('reactions', 1);
}
}
}
} else{
$this->thread->toggleReaction($reaction);
if($reaction == 'hand-thumbs-down-fill' || $reaction == 'emoji-frown-fill' ){
$user = User::find($this->thread->user->id)->decrement('reactions', 1);
}else{
$user = User::find($this->thread->user->id)->increment('reactions', 1);
}
}
$this->thread = Thread::find($this->thread->id);
}
public function replysubmit(){
$threadreply = new ThreadReply();
$threadreply->thread_id = $this->thread->id;
$threadreply->user_id = Auth::user()->id;
$threadreply->description = $this->description;
$this->description = '';
$threadreply->save();
$this->dispatchBrowserEvent('threadreplysent');
}
public function updatethread(){
$this->thread = Thread::find($this->thread->id);
}
public function render()
{
return view('livewire.thread-display');
}
}
View/threads/create.blade.php
#extends('layouts.app')
#section('stylesheets')
{{-- <link href="{{ asset('ckeditor/contents.css') }}" rel="stylesheet"> --}}
#endsection
#section('content')
<div class="container-fluid mt-5">
<form action="{{ route('thread.store',$subcategory) }}" method="POST">
#csrf
<div class="row">
<div class="col-xl-12 col-lg-12 col-sm-12 col-12 m-auto">
<div class="card shadow">
<div class="card-header">
<h4 class="card-title"> Post Thread </h4>
</div>
<div class="card-body">
<div class="form-group">
<label> Title </label>
<input type="text" class="form-control" name="title" placeholder="Enter the Title" required>
</div>
<div class="form-group" >
<label> Description </label>
<textarea class="form-control" id="description" placeholder="Enter the Description" name="description"></textarea>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-success"> Save </button>
</div>
</div>
</div>
</div>
</form>
</div>
#endsection
#section('scripts')
<script src="//cdn.ckeditor.com/4.19.0/standard/ckeditor.js"></script>
<script>
// Replace the <textarea id="editor1"> with a CKEditor 4
// instance, using default configuration.
CKEDITOR.replace( 'description' );
</script>
#endsection
View/livewire/thread-display.blade.php
#push('stylesheets')
{{-- <script src="https://cdn.ckeditor.com/ckeditor5/23.0.0/classic/ckeditor.js"></script> --}}
<style>
.parent-social {
position: relative;
}
.child-social {
width: auto !important;
bottom: 0;
right: 1rem;
margin: 1rem 0;
}
blockquote {
padding-left: 20px;
padding-right: 8px;
border-left: 5px solid #ccc;
font-style: italic;
font-family: Georgia, Times, "Times New Roman", serif;
margin: 13px 40px;
}
.reaction-parent {
position: relative;
overflow: hidden;
display: flex;
justify-content: flex-end;
}
.reaction-child {
width: 135px;
/* Position the tooltip */
position: absolute;
z-index: 1;
right: 0;
}
.reaction-parent i {
margin-right: 0.5rem;
}
.reaction-child .bi {
font-size: 1.5rem;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
#endpush
<div class="container-fluid">
<div class="row no-gutters border m-1 p-2 parent-social">
<div class="col-12 col-md-2 col-sm-12">
<div class="card d-flex justify-content-center align-items-center" style="width: 100%;">
<img src="{{ asset('/uploads/avatar/defaultavatar.webp') }}" class="" alt="..." height="auto"
width="75px">
<div class="card-body">
<h5 class="card-title text-center">{{ $thread->user->name }} <span><i class="fa fa-envelope"></i></span></h5>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">Joined: {!! date('d-M-y', strtotime($thread->user->created_at)) !!}</li>
<li class="list-group-item">Messages: 0</li>
<li class="list-group-item">Reactions: {{ $thread->user->reactions }}</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
</div>
</div>
<div class="col-12 col-sm-6 col-md-10 col-sm-12" style="overflow: hidden;">
<div class="card-body">
<h5 class="card-title">{{ $thread->title }}</h5>
</div>
<hr class="m-1">
<div style="overflow-y: scroll; height: 300px; width: 100%; overflow-x: hidden">
{!! $thread->description !!}
</div>
<div class="child-social">
<div class="reaction-parent">
<i onclick="showReactions(this)"
class="#if ($thread->isLiked()) bi bi-{{ $thread->reacted()?->type }}#else bi bi-hand-thumbs-up #endif"
style="font-size: 1.2rem; cursor: pointer;" id="reaction"></i>
<a href="#ckreply"
onclick="ckreply({{ json_encode($thread->description, 1) }},{{ json_encode($thread->user->name, 1) }})"
style="color: #000;">
<i class="bi bi-reply" style="font-size: 1.2rem;"></i>
</a>
</div>
<div class="reaction-child" style="display:none;">
<i wire:click="react('hand-thumbs-up-fill')" class="bi bi-hand-thumbs-up-fill"></i>
<i wire:click="react('hand-thumbs-down-fill')" class="bi bi-hand-thumbs-down-fill"></i>
<i wire:click="react('emoji-heart-eyes-fill')" class="bi bi-emoji-heart-eyes-fill"></i>
<i wire:click="react('emoji-frown-fill')" class="bi bi-emoji-frown-fill"></i>
<i wire:click="react('heart-fill')" class="bi bi-heart-fill"></i>
</div>
</div>
</div>
</div>
#if (count($thread->replies) > 0)
#foreach ($thread->replies as $reply)
<livewire:thread-reply :reply="$reply" :key="time() . rand(0, 999)"/>
#endforeach
#else
#endif
<div class="row no-gutters border m-1 p-2" id="ckreply" wire:ignore>
<div class="col-12 col-md-2 col-sm-12">
<div class="card d-flex justify-content-center align-items-center" style="width: 100%;">
<img src="{{ asset('/uploads/avatar/defaultavatar.webp') }}" class="" alt="..."
height="75px" width="75px">
</div>
</div>
<div class="col-12 col-sm-6 col-md-10 col-sm-12 parent-social">
<form wire:submit.prevent="replysubmit">
<div class="form-group">
<label> Reply </label>
<textarea wire:model.defer="description" class="form-control" id="description" name="description"></textarea>
</div>
<div class="form-group">
<button type="submit"
class="btn btn-primary my-2 d-flex justify-content-center align-items-center"> <i
class="bi bi-reply" style="margin-bottom: 8px; margin-right: 4px;"></i> Post
reply</button>
</div>
</form>
</div>
</div>
</div>
#push('scripts')
<script src="//cdn.ckeditor.com/4.19.0/standard/ckeditor.js"></script>
<script>
var ckdata = "";
var editor = CKEDITOR.replace('description');
// The "change" event is fired whenever a change is made in the editor.
editor.on('change', function(event) {
console.log(event.editor.getData())
#this.set('description', event.editor.getData());
ckdata = event.editor.getData();
})
window.addEventListener('threadreplysent', function() {
CKEDITOR.instances.description.setData('');
ckdata = "";
});
window.addEventListener('replyreaction', function() {
window.livewire.emit('update-thread');
});
function ckreply(description, username) {
console.log(username)
ckdata +=
`<blockquote>${username} said:${description}</blockquote><p> </p>`;
CKEDITOR.instances.description.setData(ckdata);
var editor = CKEDITOR.instances[description];
editor.focus();
}
function showReactions(ele) {
if(ele.parentNode.nextElementSibling.style.display == "none") {
ele.parentNode.nextElementSibling.style.display = "block";
} else {
ele.parentNode.nextElementSibling.style.display = "none";
}
// $('.reaction-child').toggle();
}
</script>
#endpush
View/livewire/thread-reply.blade.php
<div class="row no-gutters border m-1 p-2 parent-social">
<div class="col-12 col-md-2 col-sm-12">
<div class="card d-flex justify-content-center align-items-center" style="width: 100%;">
<img src="{{ asset('/uploads/avatar/defaultavatar.webp') }}" class="" alt="..."
height="auto" width="75px">
<div class="card-body">
<h5 class="card-title text-center">{{ $reply->user->name }}</h5>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">Joined: {!! date('d-M-y', strtotime($reply->user->created_at)) !!}</li>
<li class="list-group-item">Messages: 0</li>
<li class="list-group-item">Reactions: {{ $reply->user->reactions }}</li>
<li class="list-group-item">Vestibulum at eros</li>
</ul>
</div>
</div>
<div class="col-12 col-sm-6 col-md-10 col-sm-12" style="overflow: hidden;">
<div class="card-body">
<h5 class="card-title">{{ $reply->title }}</h5>
</div>
<hr class="m-1">
<div style="overflow-y: scroll; height: 300px; width: 100%; overflow-x: hidden">
{!! $reply->description !!}
</div>
<div class="child-social">
<div class="reaction-parent">
<i onclick="showReactions(this)"
class="#if ($reply->isLiked()) bi bi-{{ $reply->reacted()?->type }}#else bi bi-hand-thumbs-up #endif"
style="font-size: 1.2rem; cursor: pointer;"></i>
<a href="#ckreply"
onclick="ckreply({{ json_encode($reply->description, 1) }},{{ json_encode($reply->user->name, 1) }})"
style="color: #000;">
<i class="bi bi-reply" style="font-size: 1.2rem;"></i>
</a>
</div>
<div class="reaction-child" style="display:none;">
<i wire:click="react('hand-thumbs-up-fill')" class="bi bi-hand-thumbs-up-fill"></i>
<i wire:click="react('hand-thumbs-down-fill')" class="bi bi-hand-thumbs-down-fill"></i>
<i wire:click="react('emoji-heart-eyes-fill')" class="bi bi-emoji-heart-eyes-fill"></i>
<i wire:click="react('emoji-frown-fill')" class="bi bi-emoji-frown-fill"></i>
<i wire:click="react('heart-fill')" class="bi bi-heart-fill"></i>
</div>
</div>
</div>
</div>
above you see all that I wrote. I explain my situation again. When I'm writing my thread after 2-3 letters it stops writing and I have to click again to continue writing my thread. I just have this little bug otherwise everything works fine
I have a data course that has been successfully completed by the learner. Then, I want to display the course data and add a certificate download button.
I have code like this, but I get error "Trying to get property 'passing_grade' of non-object".
Controller
public function indexListCompetency()
{
$user = Auth::user('lms_web');
$course_case = DB::raw("course.id, course.title, course.cover_image, course.is_published,
CASE
WHEN COUNT(classroom.id) AND (
COUNT(group_discussion.id) OR
COUNT(competency_file.competency_id) OR
COUNT(course_activity.id)
)
THEN \"Blended\"
WHEN COUNT(classroom.id)
THEN \"Offline\"
ELSE \"Online\"
END AS course_contain");
if ($user->customer_type_id == 4) {
$course_learner = CourseLearner::select($course_case, 'course_learner.*',
DB::raw('SUM(duration) as total_duration,
CASE WHEN course.corporate_id IS NOT NULL THEN "Internal"
ELSE "External" END AS course_provider'
)
);
} else {
$course_learner = CourseLearner::select($course_case, 'course_learner.*',
DB::raw('SUM(duration) as total_duration,
CASE WHEN course.hotel_id IS NOT NULL THEN "Internal"
ELSE "External" END AS course_provider'
)
);
}
$course_taken = $course_learner
->where('learner_id', auth('lms_web')->user()->id)
->join('course', 'course.id', 'course_learner.course_id')
->leftJoin('group_discussion','group_discussion.course_id','course.id')
->leftJoin('classroom','classroom.course_id','course.id')
->leftJoin('course_activity','course_activity.course_id','course.id')
->leftJoin('competency_file','competency_file.competency_id','course.id')
->join('file_assignment', 'file_assignment.id', 'competency_file.file_assignment_id')
->orderByDesc('course_learner.updated_at')
->groupBy('course_learner.id', 'course_learner.course_id', 'course_learner.trainer_id',
'course_learner.batch_id', 'course_learner.learner_id', 'course_learner.open_at', 'course_learner.close_at',
'course_learner.created_at', 'course_learner.updated_at', 'course_learner.is_complete',
'course.id', 'course.title', 'course.cover_image', 'course.is_published');
$progress = Progress::select('course_id', DB::raw('SUM(value) as progress'))
->where('user_id', auth('lms_web')->user()->id)
->groupBy('course_id')
->get();
$user_courses = $course_taken->get();
$complete = 0;
// dd($user_courses);
foreach ($user_courses as $key => $item) {
foreach ($progress as $items) {
if ($item->course_id == $items->course_id) {
if ($item->total_duration <= $items->progress) {
$complete++;
}
}
}
$abc = $progress;
// Certificate of Completion
$cert_comp = new CertificateNumber;
$cert_comp->set_completion($user->id, $item->course_id, $user->def_corporate_id, $user->def_hotel_id);
$cert_comp_num = $cert_comp->getID();
// Certificate of Completion
$cert_att = new CertificateNumber;
$cert_att->set_attainment($user->id, $item->course_id, $user->def_corporate_id, $user->def_hotel_id);
$cert_att_num = $cert_att->getID();
$user_courses[$key]['cert_completion_num'] = $cert_comp_num;
$user_courses[$key]['cert_attainment_num'] = $cert_att_num;
$user_courses[$key]['course'] = $cert_comp->course;
// dd($item->course);
}
switch ($user->customer_type_id) {
case 4:
$company = Corporate::find($user->def_corporate_id);
break;
default:
$company = Hotel::find($user->def_hotel_id);
break;
}
return view('learning.listcompetency.index', compact('cert_comp_num','user', 'user_courses', 'progress', 'complete', 'company'));
}
Blade View
#forelse($user_courses as $item)
#if ($item->course_provider == 'External')
#foreach ($progress as $items)
#if($items->course_id == $item->course_id)
#if ($item->total_duration != 0)
#if (round(($items->progress/$item->total_duration)*100) >= 100)
<li class="list-group-item">
<div class="row mycourse-list">
<div class="col-2">
<img src="{{ asset($item->cover_image) }}" class="img-cover-list">
<div class="course-lang type-paragraph2" >
#if($item->course_lang == 1)
<img class="rounded-circle" src="{{ asset('img/icon/id_square.png') }}" alt="ID">
#else
<img class="rounded-circle" src="{{ asset('img/icon/uk_square.png') }}" alt="ENG">
#endif
</div>
<div class="course-status type-paragraph2 published">FREE</div>
</div>
<div class="col-6 course-list">
<div class="course-detail type-paragraph5">
<div class="course-type">
AJAR <span class="course-mode">• {{ $item->course_contain }}</span>
</div>
<div class="learner-course-info" style="margin-top: 0px;">
{{ $item->title }}
</div>
<div class="type-paragraph3" style="color: #7cdb4a;">
Completion Date : {{ Carbon\Carbon::parse($item->updated_at)->format('M d, Y') }}
</div>
</div>
</div>
<div class="col-2 course-list">
{{-- <a href="#" data-toggle="modal" data-target=".completion-cert-modal-{{ $item->course_id }}"
data-id="{{ $item->course_id }}"
data-coursename="{{ $item->course->title }}"
data-date="{{ Carbon\Carbon::parse($item->updated_at)->format('M d, Y') }}"
class="btn btn-secondary-outline certificate">
Certificate
</a> --}}
<div class="dropdown">
<button class="btn btn-secondary-outline dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Certificate
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a href="#" data-toggle="modal" data-target=".completion-cert-modal-{{ $item->id . $item->learner_id . '1' }}"
data-id="{{ $item->id }}"
data-coursename="{{ $item->title }}"
data-date="{{ \Carbon\Carbon::parse($item->updated_at)->format('M d, Y') }}"
class="dropdown-item certificate">
Certificate of Completion
</a>
#if ($item->course->passing_grade != 'N/A' && $item->course->score >= $item->course->passing_grade)
<a href="#" data-toggle="modal" data-target=".attainment-cert-modal-{{ $item->id . $item->learner_id . '2' }}"
data-id="{{ $item->id }}"
data-coursename="{{ $item->title }}"
data-date="{{ \Carbon\Carbon::parse($item->updated_at)->format('M d, Y') }}"
class="dropdown-item certificate-attainment">
Certificate of Attainment
</a>
#endif
</div>
{{-- Modal Preview Certificate of Completion --}}
<div class="modal fade completion-cert-modal-{{ $item->id . $item->learner_id . '1' }}" tabindex="-1" role="dialog" aria-labelledby="completionCertModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Certificate of Completion</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="cert-preview embed-responsive-item" src="{{ route('lms.custom_certificate.preview', ['pfx'=>$pfx, 'id' => $item->cert_completion_num])}}"></iframe>
</div>
<label class="pt-4">CERT ID:</label>
<div class="input-group">
<input type="text" class="form-control" id="cert_id_{{ $item->id . $item->learner_id . '1' }}" placeholder="your CERT ID" aria-label="your CERT ID" aria-describedby="basic-addon2" value="{{ $item->cert_completion_num }}" readonly style="background: #fff" onclick="javascript:$(this).select()">
<div class="input-group-append">
<button class="btn btn-outline-secondary copy-text" style="border-radius: 0 .25rem .25rem 0; padding: 5px 10px !important;" type="button" onclick="copyText('cert_id_{{ $item->id . $item->learner_id . '1' }}')"> Copy! </button>
</div>
</div>
<label class="pt-2">Validation URL:</label>
<div class="input-group">
<input type="text" class="form-control" id="cert_url_{{ $item->id . $item->learner_id . '1' }}" placeholder="your CERT ID" aria-label="your CERT ID" aria-describedby="basic-addon2" value="{{ route('lms.custom_certificate.verified', ['id' => $item->cert_completion_num]) }}" readonly style="background: #fff" onclick="javascript:$(this).select()">
<div class="input-group-append">
<button class="btn btn-outline-secondary copy-text" style="border-radius: 0 .25rem .25rem 0; padding: 5px 10px !important;" type="button" onclick="copyText('cert_url_{{ $item->id . $item->learner_id . '1' }}')"> Copy! </button>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
Download
</div>
</div>
</div>
</div>
{{-- End Modal Preview Certificate of Completion --}}
#if ($item->course->passing_grade != 'N/A' && $item->course->score >= $item->course->passing_grade)
<!-- Modal Preview Certificate of Attainment -->
<div class="modal fade attainment-cert-modal-{{ $item->id . $item->learner_id . '2' }}" tabindex="-1" role="dialog" aria-labelledby="attainmentCertModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Certificate of Attainment</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body text-left">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="cert-preview embed-responsive-item" src="{{ route('lms.attainment_certificate.preview', ['pfx'=>$pfx, 'id' => $item->cert_attainment_num]) }}"></iframe>
</div>
<label class="pt-4">CERT ID:</label>
<div class="input-group">
<input type="text" class="form-control" id="cert_id_{{ $item->id . $item->learner_id . '2' }}" placeholder="your CERT ID" aria-label="your CERT ID" aria-describedby="basic-addon2" value="{{ $item->cert_attainment_num }}" readonly style="background: #fff" onclick="javascript:$(this).select()">
<div class="input-group-append">
<button class="btn btn-outline-secondary copy-text" style="border-radius: 0 .25rem .25rem 0; padding: 5px 10px !important;" type="button" onclick="copyText('cert_id_{{ $item->id . $item->learner_id . '2' }}')"> Copy! </button>
</div>
</div>
<label class="pt-2">Validation URL:</label>
<div class="input-group">
<input type="text" class="form-control" id="cert_url_{{ $item->id . $item->learner_id . '2' }}" placeholder="your CERT ID" aria-label="your CERT ID" aria-describedby="basic-addon2" value="{{ route('lms.custom_certificate.verified', ['id' => $item->cert_attainment_num]) }}" readonly style="background: #fff" onclick="javascript:$(this).select()">
<div class="input-group-append">
<button class="btn btn-outline-secondary copy-text" style="border-radius: 0 .25rem .25rem 0; padding: 5px 10px !important;" type="button" onclick="copyText('cert_url_{{ $item->id . $item->learner_id . '2' }}')"> Copy! </button>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
Download
</div>
</div>
</div>
</div>
<!-- End Modal Preview Certificate of Attainment -->
#endif
</div>
</div>
<div class="col-2 course-list">
<a href="{{ route('lms.courses.overview', ['pfx' => $pfx, 'id' => $item->course_id]) }}"
class="btn btn-secondary-outline">See Detail</a>
</div>
</div>
</li>
#php $completed++; #endphp
#endif
#endif
#endif
#endforeach
#else
<div class="empty-internal-course">
<img src="{{ asset('img/empty-learning-passport.png') }}" class="img-responsive"
style="padding:20px;" alt="Empty learning passport">
<div class="data-empty">
You haven’t completed any courses this time.
</div>
</div>
#break
#endif
#empty
<div class="empty-internal-course">
<img src="{{ asset('img/empty-learning-passport.png') }}" class="img-responsive"
style="padding:20px;" alt="Empty learning passport">
<div class="data-empty">
You haven’t completed any courses this time.
</div>
</div>
#endforelse
FYI. There should be more than one course data displayed and click download certificate.
How to fix it? Thank you 🙏
I have a script when I display all what is in collection, I use foreach. One of all collection you can delete clicking specific button, but the problem is you can click collection with ID 17 and it will delete first existing collection, even with id = 1. I do not know what to do because i think that everything looks ok. When I dump controller I see first existing collection id. I mean that moment -> ReviewAnswerController#destroy in code
Can you help me?
#foreach($data->reviewAnswers as $answer)
<div class="row">
<div class="col-md-12" style="position: inherit; display: flow-root; float: right; background: #94969f; margin-top: 15px; margin-right: 15px; padding: 5px; border-radius: 5px; width: 80%; color: white; padding-bottom: 3px;">
<div class="col-md-1">
<?php $avAnswer = App\Models\UserData::where('user_id', $data->sender_id)->first() ?>
#if(empty($avAnswer->avatar))
<img src="{{ asset('img/lock_thumb.jpg')}}" style="width: 50px; height: 50px; border: 2px solid white;border-radius: 50%;">
#else
<img src="{{ asset('/storage/uploads/avatars/'. $av->avatar) }}" style="width: 50px; height: 50px; border: 2px solid white;border-radius: 50%;">
#endif
</div>
<div class="col-md-5">
<div style="float: left;">
{{$answer->id}}
<b>{{$answer->sender_name}} {{$answer->sender_surname}}</b> |
#if($answer->sender_role_specific)
{{$answer->sender_club_role}} ({{$answer->sender_role_specific}})
#else
{{$answer->sender_club_role}}
#endif
</div>
</div>
<div class="col-md-5"></div>
<div class="col-md-1">
#if(Auth::user()->role == 'admin')
<form id="reviewAnswerForm" action="{{ action('ReviewAnswerController#destroy', $answer->id) }}" method="POST">
{{ method_field('DELETE') }} {{ csrf_field() }}
<button class="btn" style="background-color:transparent; float: right;">
<img src="{{ asset('img/review-icons/delete.png')}}" style="float: right;"/>
</button>
</form>
#endif
</div>
<div class="col-md-11" style="border-top: 1px solid; padding-bottom: 5px;">
<p>{{$answer->answer}}</p>
<button class="btn" style="background-color:transparent; float: right;" data-toggle="modal" data-target="#modalreportanswer">
<img src="{{ asset('img/review-icons/report.png')}}" style="width: 15px; height: 15px; float: right; margin-top: 10px;">
</button>
<div class="modal fade" id="modalreportanswer" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">#lang('main.report')</h4>
</div>
<div class="modal-body">
<form action="{{ action('ReviewAnswerReportController#store') }}" method="POST" class="">
{{ csrf_field() }}
<div class="form-group">
<label for="comment">#lang('main.reason'):</label>
<textarea id="text" class="form-control noresize" rows="5" name="reason"></textarea>
<h6 class="pull-right" id="count_message"></h6>
</div>
<div class="form-group">
<input type="hidden" class="form-control" value="{{ $answer->id }}" name="reviewAnswerId">
</div>
<button class="btn btn-primary" type="submit">#lang('main.report')!</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endforeach
In your code you have 2 method, POST and DELETE in the same Form
<form id="reviewAnswerForm" action="{{ action('ReviewAnswerController#destroy', $answer->id) }}" method="POST">
{{ method_field('DELETE') }} {{ csrf_field() }}
Try with this , I use Laravel Collective , it is very clear.
Route::delete('answer/{id}', ['as' => 'reviewAnswer.destroy', 'uses' => 'ReviewAnswerController#destroy'] );
#if(Auth::user()->role == 'admin')
{!! Form::open(['method' => 'DELETE','route' => ['reviewAnswer.destroy',
$answer->id, ] ]) !!}
#endif
I'm trying to tackle a "two forms on one page" issue with my PHP code, but its turning out to be more tirkcy than I expected, and just isn't behaving in the correct way as I thought it would.
For the first form (Login) I'm using this if statement to determine if the message if for the Login.
#if(Session::has('message') && Session::get('last_message_for') == 'login')
<div class="notification is-{{ Session::get('color') }}">
<i class="fa fa-times"></i> {{ Session::get('message') }}
</div>
#elseif($errors->first() && Session::get('last_message_for') == 'login')
<div class="notification is-warning">
<i class="fa fa-times"></i> {{ $errors->first() }}
</div>
#endif
I've got the same code for my second form, but it just checks the last_message_for for a different value to 'login'.
#if(Session::has('message') && Session::get('last_message_for') == 'modal')
<div class="modal is-active" id="modal-forgotPassword">
#else
<div class="modal" id="modal-forgotPassword">
#endif
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title" id="open-modal">Forgot Password?</p> <button class="delete"></button>
</header>
<form action="{{ route('frontend.guest.password.forgot') }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<section class="modal-card-body">
<div class="content">
#if(Session::has('message') && Session::get('last_message_for') == 'modal')
<div class="notification is-{{ Session::get('color') }}">
<i class="fa fa-times"></i> {{ Session::get('message') }}
</div>
#endif
<div class="field">
<p class="control has-icons-left">
<input class="input" name="email" placeholder="Enter an email..." type="email">
<span class="icon is-small is-left"><i class="fa fa-envelope"></i></span>
</p>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</div>
</section>
<footer class="modal-card-foot">
<button class="button is-success" type="submit"><i class="fa fa-sign-in"></i> Send email</button>
</footer>
</form>
</div>
</div>
Now down to the issue, the Login part works perfectly fine and shows the error messages when there are any for it, but the second one isn't showing any errors when I have some.
I'm using this to set the last_message_for
Session::put('last_message_for', 'login');
Here is the code for my second form:
public function onForgotPassword(Request $request) {
$validator = Validator::make($request->all(), [
'email' => 'required|email|exists:users,mail',
]);
Session::put('last_message_for', 'modal');
if ( $validator->fails()) {
return redirect()->route('frontend.guest.login')->withErrors($validator->messages());;
}
else {
Mail::to($request->input('email'))->send(new ForgotPasswordEmail());
return redirect()->route('frontend.guest.login')->withMessage('Email Sent')->withColor('warning');
}
}
You're not handling validation errors, only the messages returned, this should do it.
#if(Session::has('message') && Session::get('last_message_for') == 'modal')
<div class="notification is-{{ Session::get('color') }}">
<i class="fa fa-times"></i> {{ Session::get('message') }}
</div>
#elseif($errors->first() && Session::get('last_message_for') == 'login')
<div class="notification is-warning">
<i class="fa fa-times"></i> {{ $errors->first() }}
</div>
#endif
I have two forms in the same page so you can easily assign it error to each form using flash session
in your controller just use session like this line
use Session;
this code related to two search forms
//searchInHistory
public function searchInHistory(){
$date = Request()->all();
$rules = [
'dateFrom' =>'required',
'dateTo' =>'required',
];
$validator = Validator($date,$rules);
if ($validator->fails()){
Session::flash('inError', 'inError');
return redirect()
->back()
->withErrors($validator)
->withInput();
}else{
$store = DB::table('stores')->select(
'store_details.id',
'store_details.status',
'stores.id AS storeId',
'stores.partNo',
'stores.title',
'store_details.serialNo',
'store_details.created_at',
'store_details.updated_at'
)
->join('store_details', 'store_details.storeId', '=', 'stores.id')
->where('store_details.status','inside')
->whereBetween('store_details.created_at',[$date['dateFrom'],$date['dateTo']])
->get();
return view('crm.store.in',compact('store'));
}
}
//===============
//searchHistory
public function searchOutHistory(){
$date = Request()->all();
$rules = [
'dateFrom' =>'required',
'dateTo' =>'required',
];
$validator = Validator($date,$rules);
if ($validator->fails()){
Session::flash('inError', 'inError');
return redirect()
->back()
->withErrors($validator)
->withInput();
}else{
$store = DB::table('stores')->select(
'store_details.id',
'store_details.status',
'stores.id AS storeId',
'stores.partNo',
'stores.title',
'store_details.serialNo',
'store_details.created_at',
'store_details.updated_at'
)
->join('store_details', 'store_details.storeId', '=', 'stores.id')
->where('store_details.status','outside')
->whereBetween('store_details.updated_at',[$date['dateFrom'],$date['dateTo']])
->get();
return view('crm.store.out',compact('store'));
}
}
//===============
the following code above each error assigned to specific form using session
this is blade code view code related to two form
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Store IN / OUT Control</h3>
</div>
<div class="row">
<div class="col-md-6">
<div class="box-body">
#if(session('outError'))
#if ($errors->any())
<div class="alert alert-danger">
<center>
#foreach ($errors->all() as $error)
{{ $error }}<br>
#endforeach
</center>
</div>
#endif
#endif
#if(session('out'))
#if(session('save'))
<div class="alert alert-success">
<center>
Products Came out of Successfully
</center>
</div>
#endif
#endif
<!-- form start -->
<form role="form" method="post" action="{{url('admin/takeProductOutStore')}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="box-body">
<input type="hidden" name="id" value="{{$storeId}}">
<div class="form-group">
<label>Products in Store</label>
<select multiple class="form-control" name="products[]" required>
#foreach($InDoorProducts as $row)
<option value="{{$row->serialNo}}">{{$row->serialNo}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label>Date</label>
<input type="date" class="form-control" name="date" required>
</div>
<div class="form-group">
<textarea class="textarea" required placeholder=" Write Notes"style="width: 100%; height: 125px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;" name="note" value="{{old('note')}}"></textarea>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">Out Store <b>→</b></button>
</div>
</form>
</div>
</div>
<div class="col-md-6">
<div class="box-body">
#if(session('inError'))
#if ($errors->any())
<div class="alert alert-danger">
<center>
#foreach ($errors->all() as $error)
{{ $error }}<br>
#endforeach
</center>
</div>
#endif
#endif
#if(session('in'))
#if(session('save'))
<div class="alert alert-success">
<center>
Products Added to Store Again Successfully
</center>
</div>
#endif
#endif
<!-- form start -->
<form role="form" method="post" action="{{url('admin/takeProductInStore')}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="box-body">
<input type="hidden" name="id" value="{{$storeId}}">
<div class="form-group">
<label>Products Out Store</label>
<select multiple class="form-control" name="products[]" required>
#foreach($OutDoorProducts as $row)
<option>{{$row->serialNo}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label>Date</label>
<input type="date" class="form-control" name="date" required>
</div>
<div class="form-group">
<textarea class="textarea" required placeholder=" Write Notes"style="width: 100%; height: 125px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;" name="note" value="{{old('note')}}"></textarea>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">Back To Store <b>←</b></button>
</div>
</form>
</div>
</div>
</div>
</section>