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
Related
I have created a controller, model and view for the Profile menu, but when I try to update my own profile, the data cannot be updated and the ERROR message is not found.
this is the ProfileController.php file:
enter code here
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use App\Profile;
class ProfileController extends Controller
{
public function edit($id)
{
return view('profile.profile',compact('id'));
}
public function update(Request $request, $id)
{
$profile = Profile::find($id)->first();
$this->validate($request, [
"name" => 'required|string',
"email" => 'required|email|unique:users',
"alamat" => 'required',
"nohp" => 'required',
"password" => 'required|confirmed|min:8',
]);
if ($request->has('password')){
$profile->name = $request->name;
$profile->email = $request->email;
$profile->alamat = $request->alamat;
$profile->nohp = $request->nohp;
$profile->password = bcrypt($request->password);
}
else{
$profile->name = $request->name;
$profile->email = $request->email;
$profile->alamat = $request->alamat;
$profile->nohp = $request->nohp;
}
$profile->save();
return redirect()->back();
}
this is the profile.php file:
enter code here
#extends('layouts.app')
#section('content')
<div class="container bg-white">
<!-- Content Header -->
<div class="content-header">
<!-- CARD PROFILE -->
<section class="content">
<div class="container-fluid">
<div class="col-md-12">
<div class="row">
<div class="col-md-4">
<div class="card card-warning" style="border-top-left-radius:40px; border-top-right-radius:40px;">
<div class="card-body box-profile" style="margin-top: 10px; margin-bottom: 10px;">
<img src="{{asset('adminlte/dist/img/user.png')}}" class="img-circle elevation-2" style="width:140px; height: 140px; margin-left: 85px; margin-bottom: 10px;" alt="User Image" align="center">
<h3 align="center"><strong>{{Auth::user()->name}}</strong></h3>
</div>
</div>
<div class="card card-warning" style="margin-top: 15px; border-radius:40px;">
<div class="card-header" style="background-image: linear-gradient(#40E0D0,#40E0D0);">
<h4 class="card-tittle" align="center"><strong>Tentang Saya</strong></h4>
</div>
<div class="card-body" style="font-family:glacial-indiference;">
<strong><img src="{{asset('adminlte/dist/img/email.png')}}" style="width:30px; height: 30px; margin-left: 7px; margin-right: 4px"
> Email</strong>
<p class="text-muted" style="margin-left: 45px">{{Auth::user()->email}}</p>
<hr>
<strong><img src="{{asset('adminlte/dist/img/address.png')}}" style="width:30px; height: 30px; margin-left: 7px; margin-right: 4px"
> Alamat</strong>
<p class="text-muted" style="margin-left: 45px">{{Auth::user()->alamat}}</p>
<hr>
<strong><img src="{{asset('adminlte/dist/img/phone.png')}}" style="width:30px; height: 30px; margin-left: 6px; margin-right: 6px"
> No. Telp</strong>
<p class="text-muted" style="margin-left: 45px">{{Auth::user()->nohp}}</p>
<hr>
</div>
</div>
</div>
<div class="col-md-8">
<div class="card col-md-12" style="border-top-right-radius:40px; border-bottom-left-radius:40px;">
<h4 class="card-tittle" align="center" style="margin-top:20px">
<strong>Edit Profile</strong>
</h4>
<form action="{{ route('profile.profile', $id) }}" method="post" enctype="multipart/form-data" style="width:95%; margin-left:16px"> #method('patch')
#csrf
<div class="form-group">
<label for="name">Nama</label>
<input type="text" class="form-control" name="name" value="{{Auth::user()->name}}" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" name="email" value="{{Auth::user()->email}}" required>
</div>
<div class="form-group">
<label for="alamat">Alamat</label>
<input type="text" class="form-control" name="alamat" value="{{Auth::user()->alamat}}" required>
</div>
<div class="form-group">
<label for="nohp">NoHP</label>
<input type="text" class="form-control" name="nohp" value="{{Auth::user()->nohp}}" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password">
<label>*) Jika Password tidak diganti, kosongkan saja.</label>
</div>
<div class="form-group" align="center" style="margin-top: 30px; margin-bottom: 30px;">
<button type="submit" class="btn btn-block" style=" border-radius:30px; background-image: linear-gradient(#40E0D0,#40E0D0); width:60%; height:20%"
>Perbaharui</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
#endsection
enter code here
when run, the result will be like this:
data before updating
the data after being replaced and the results are back as before:
the data after being replaced and the results are back as before
I don't know where the error is because there is no ERROR message.
I need your help to solve this problem
You are not updating the record you are trying to find by 'id'. Profile::find($id)->first(); is finding the record with the primary key $id and then doing a new query to get the "first" record from the table. So $profile is not the record you are trying to find by 'id'; you are updating the wrong record (the same wrong record) every time.
$profile = Profile::findOrFail($id);
We will use findOrFail to not have to deal with any null being returned if it can't find a record.
On a side note, the if/else could use some cleaning:
if ($request->has('password')) {
$profile->password = bcrypt($request->password);
}
$profile->name = $request->name;
...
I just can't get my head around this.
I want to fetch product images/items from the database and show in a carousel. But i want to have 3 images/items on each slide.
I have tested that it work by just hardcoding/repeating the code, but i want it to work in the foreach loop that i run from the result of the database question. But i just cant get it to work properly.
Here is my code that i am working on.
<div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner"> <?php
$x=0;
foreach($result as $r)
{
if (($x % 3) == 0)
{?>
<div class="carousel-item <?php if($x == 0){ echo "active"; }?>">
<div class="album py-5 bg-light">
<div class="container">
<div class="row"><?php
}?>
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<img class="card-img-top" style="max-height: 300px"
src="../productimages/<?php echo $r['pid']."/".$r['filename']; ?>"
alt="Card image cap">
<div class="card-body">
<p class="card-text">This is a wider card with supporting text
below as a natural lead-in to additional content. This content
is a little bit longer.</p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
</div>
<small class="text-muted">9 mins</small>
</div>
</div>
</div>
</div><?php
if (($x % 3) == 0)
{?>
</div>
</div>
</div>
</div><?php
}
$x++;
}?>
</div>
<button class="carousel-control-prev"
style="width: 3.5%; height: 200px; top: 30%;" type="button"
data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"><i
class="bi bi-arrow-left-square-fill text-warning" fill="black"
style="font-size: 50px; position: relative; top: -23px;"></i></span> <span
class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next"
style="width: 3.5%; height: 200px; top: 30%;" type="button"
data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
<span class="carousel-control-next-icon bs-orange" aria-hidden="true"><i
class="bi bi-arrow-right-square-fill text-warning"
style="font-size: 50px; position: relative; top: -23px;"></i></span> <span
class="visually-hidden">Next</span>
</button>
</div>
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();
I have a user profile screen which shows a user's information along with a profile picture. There I have a link called "Change Photo" which triggers a file input to upload a new image. Then I have a JS code to submit the form soon after the file input takes the image. But once the form is submitted, at my controller, when I dump my request, the filebag is empty.
This is my .twig file
{% extends('base.html.twig') %}
{% block title %}Welcome- Open Rpoad Tolling!{% endblock %}
{% block stylesheets %}
<style>
body{
background: -webkit-linear-gradient(left, #3931af, #00c6ff);
}
.emp-profile{
padding: 3%;
margin-top: 3%;
margin-bottom: 3%;
border-radius: 0.5rem;
background: #fff;
}
.profile-img{
text-align: center;
}
.profile-img img{
width: 70%;
height: 100%;
}
.profile-img .file {
position: relative;
overflow: hidden;
margin-top: -20%;
width: 70%;
border: none;
border-radius: 0;
font-size: 15px;
background: #212529b8;
}
.profile-img .file input {
position: absolute;
opacity: 0;
right: 0;
top: 0;
}
.profile-head h5{
color: #333;
}
.profile-head h6{
color: #0062cc;
}
.profile-edit-btn{
border: none;
border-radius: 1.5rem;
width: 70%;
padding: 2%;
font-weight: 600;
color: #6c757d;
cursor: pointer;
}
.profile-edit-btn:hover{
color: #FFF;
background: rgb(240, 173, 78, 0.75);
/*border: 2px solid rgba(240, 173, 78, 0.75);*/
}
.proile-rating{
font-size: 12px;
color: #818182;
margin-top: 5%;
}
.proile-rating span{
color: #495057;
font-size: 15px;
font-weight: 600;
}
.profile-head .nav-tabs{
margin-bottom:5%;
}
.profile-head .nav-tabs .nav-link{
font-weight:600;
border: none;
}
.profile-head .nav-tabs .nav-link.active{
border: none;
border-bottom:2px solid #0062cc;
}
.profile-work{
padding: 14%;
margin-top: -15%;
}
.profile-work p{
font-size: 12px;
color: #818182;
font-weight: 600;
margin-top: 10%;
}
.profile-work a{
text-decoration: none;
color: #495057;
font-weight: 600;
font-size: 14px;
}
.profile-work ul{
list-style: none;
}
.profile-tab label{
font-weight: 600;
}
.profile-tab p{
font-weight: 600;
color: #0062cc;
}
</style>
{% endblock %}
{% block body %}
<div class="container emp-profile">
<form action="{{ path('changeImage') }}" name="changeProfilePhoto" id="changeImageForm" method="post" enctype="multipart/form-data" >
<div class="row">
<div class="col-md-4">
<div class="profile-img">
<img src="{{ photoSrc }}" alt=""/>
<div class="file btn btn-lg btn-primary" id="fileUploadButton">
Change Photo
</div>
</div>
</div>
<div class="col-md-6">
<div class="profile-head">
<h5>
{{ user.firstName }} {{ user.lastName }}
</h5>
<h6>
Web Developer and Designer
</h6>
<p class="proile-rating">RANKINGS : <span>8/10</span></p>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">About</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Timeline</a>
</li>
</ul>
</div>
</div>
<div class="col-md-2">
<button type="button" onclick="window.location.href = '{{ editProfile }}';" class="profile-edit-btn" name="btnAddMore" >Edit Profile</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="profile-work">
<p>WORK LINK</p>
Website Link<br/>
Bootsnipp Profile<br/>
Bootply Profile
<p>SKILLS</p>
Web Designer<br/>
Web Developer<br/>
WordPress<br/>
WooCommerce<br/>
PHP, .Net<br/>
</div>
</div>
<div class="col-md-8">
<div class="tab-content profile-tab" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<div class="row">
<div class="col-md-6">
<label>User Id</label>
</div>
<div class="col-md-6">
<p>Kshiti123</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Name</label>
</div>
<div class="col-md-6">
<p>Kshiti Ghelani</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Email</label>
</div>
<div class="col-md-6">
<p>kshitighelani#gmail.com</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Phone</label>
</div>
<div class="col-md-6">
<p>123 456 7890</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Profession</label>
</div>
<div class="col-md-6">
<p>Web Developer and Designer</p>
</div>
</div>
</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
<div class="row">
<div class="col-md-6">
<label>Experience</label>
</div>
<div class="col-md-6">
<p>Expert</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Hourly Rate</label>
</div>
<div class="col-md-6">
<p>10$/hr</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Total Projects</label>
</div>
<div class="col-md-6">
<p>230</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>English Level</label>
</div>
<div class="col-md-6">
<p>Expert</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Availability</label>
</div>
<div class="col-md-6">
<p>6 months</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<label>Your Bio</label><br/>
<p>Your detail description</p>
</div>
</div>
</div>
</div>
</div>
</div>
<input type="file" id="changeImageButton" name="file"/>
</form>
</div>
<script>
const changeImgButton = document.getElementById('changeImageButton');
const fileUploadButton = document.getElementById('fileUploadButton');
const formHome = document.getElementById('changeImageForm');
changeImgButton.addEventListener("change",function () {
formHome.submit();
});fileUploadButton.addEventListener("click",function () {
changeImgButton.click();
});
</script>
{% endblock %}
// This is my controller
/**
* #Route("/changeImage", name="changeImage")
* #param Request $request
*/
public function changeImage(Request $request){
$file = $request->files->get('file');
dump($request);die;
if($file){
$fileName = md5(uniqid()).'.'.$file->guessExtension();
$file->move(
$this->getParameter('uploads_dir'), $fileName
);
}
}
In laravel5 instead of using foreach I can use the if statement to filter the data on the basis of SQL query. How can I view my page using ifelse statement in laravel5? I have three div class in these class how to fetch the data from the database? How to use in the blade.php file?
How can I filter the data from database using routes and controller?
<div class="container">
<div class="block-content block-content-small-padding">
<div class="block-content-inner">
<h2 class="center">Recent Properties</h2>
<ul class="properties-filter">
<li class="selected"><span>All</span></li>
<li><a href="#" class="featured" data-filter=".featured" ><span>Featured</span></a></li>
<li><a href="#" class="rent" data-filter=".rent" ><span>Rent</span></a></li>
<li><a href="#"class="sale" data-filter=".sale" ><span>Sale</span></a></li>
</ul>
<div class="properties-items isotope" style="position: relative; overflow: hidden; height: 810px;">
<div class="row ">
#if($val -> $value)
<div class="property-item col-sm-6 col-md-3 isotope-item my " style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
<div class="property-box">
<div class="property-box-inner">
<h3 class="property-box-title">{{$value->city}}</h3>
<h4 class="property-box-subtitle">{{$value->state}}</h4>
<div class="property-box-picture">
<div class="property-box-price">{{$value->property_price}}</div>
<div class=""> <img src="images/test/{{$value->image}}" alt=""> </div>
</div>
</div>
</div>
</div>
#elseif($val -> $value)
<div class="property-item col-sm-6 col-md-3 isotope-item" style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
<div class="property-box">
<div class="property-box-inner">
<h3 class="property-box-title">{{$value->city}}</h3>
<h4 class="property-box-subtitle">{{$value->state}}</h4>
<div class="property-box-picture">
<div class="property-box-price">{{$value->property_price}}</div>
<div class=""> <img src="images/test/{{$value->image}}" alt=""> </div>
</div>
</div>
</div>
</div>
#else($val -> $value)
<div class="property-item property-sale col-sm-6 col-md-3 isotope-item myButton my" style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
<div class="property-box">
<div class="property-box-inner">
<h3 class="property-box-title">{{$value->city}}</h3>
<h4 class="property-box-subtitle">{{$value->state}}</h4>
<div class="property-box-picture">
<div class="property-box-price">{{$value->property_price}}</div>
<div class=""> <img src="images/test/{{$value->image}}" alt=""> </div>
</div>
</div>
</div>
</div>
#endif
Controller:
public function index()
{
$view=DB::table('property_details')
->get();
return View::make('index', array('val'=>$view));
}
public function rentshow()
{
$show=DB::table('property_details')
->where('sale_or_rent','=','rent')
->get();
return View::make('index', array('val'=>$show));
}
public function saleshow()
{
$show=DB::table('property_details')
->where('sale_or_rent','=','sale')
->get();
return View::make('index', array('val'=>$show));
}
You need to correct your if / else statements to:
#if ( $val == "something" )
// do something
#elseif ( $val == "something-else" )
// do something else
#else
// the default
#endif
You can't pass a condition to #else like you've done in your code.