I have a searching bar in my learn project. I include it to the navbar.blade.php and when testing that it becomes that url construction.
localhost:8890/home?_token=7dKh256Me65Wb0rCvlJWkkk1SKdGrpaRPFCHP7MW&_method=GET&search=test
But the controller isn´t calling. I need this url to make it work:
localhost:8890/search?_token=7dKh256Me65Wb0rCvlJWkkk1SKdGrpaRPFCHP7MW&_method=GET&search=test
My route:
Route::get('search', [App\Http\Controllers\ProductController::class, 'search'])->name('search');
ProductController:
public function search(Request $request)
{
//Get the search vale from the request
$search = $request->input('search');
$products = Product::query()
->where('ean', 'LIKE', "%{$search}%")
->orWhere('manufacturer', 'LIKE', "%{$search}%")
->orWhere('name', 'LIKE', "%{$search}%")
->orWhere('productNumber', 'LIKE', "%{$search}%")
->orWhere('propertie', 'LIKE', "%{$search}%")
->get();
return view('products.search',compact('products'));
}
Included navbar-search.blade.php
<!-- Right navbar links -->
<ul class="navbar-nav ml-auto">
<!-- Navbar Search -->
<li class="nav-item">
<a class="nav-link" data-widget="navbar-search" role="button">
<i class="fas fa-search"></i>
</a>
<div class="navbar-search-block">
<form class="form-inline">
#csrf
<div class="input-group input-group-sm">
<input type="text" name="search" class="form-control form-control-navbar" placeholder="Search" required>
<div class="input-group-append">
<form action="{{route('search')}}" method="GET">
#csrf
#method('GET')
<button class="btn btn-navbar" type="submit">
<i class="fas fa-search"></i>
</button>
</form>
<button class="btn btn-navbar" type="button" data-widget="navbar-search">
<i class="fas fa-times"></i>
</button>
</div>
</div>
</form>
</div>
</li>
</ul>
As said by Sharma in the comments before, you shouldn't use 2 form nested. Controller isn´t calling because first form doesn't set action. You can edit it like this:
<ul class="navbar-nav ml-auto">
<!-- Navbar Search -->
<li class="nav-item">
<a class="nav-link" data-widget="navbar-search" role="button">
<i class="fas fa-search"></i>
</a>
<div class="navbar-search-block">
<form class="form-inline" action="{{route('search')}}" method="GET">
<div class="input-group input-group-sm">
<input type="text" name="search" class="form-control form-control-navbar" placeholder="Search" required>
<div class="input-group-append">
<button class="btn btn-navbar" type="submit">
<i class="fas fa-search"></i>
</button>
<button class="btn btn-navbar" type="button" data-widget="navbar-search">
<i class="fas fa-times"></i>
</button>
</div>
</div>
</form>
</div>
</li>
</ul>
Related
I am working on a Laravel project and I want to display currently authenticated users posts in view file, I am getting an error while trying to achieve that says
"Class name must be a valid object or a string"...
my blade view
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Swap
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
#foreach($data as $dat)
<div class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4">
<img
src="{{asset('images/' . $dat->imogi)}}"
alt="Trendy Pants and Shoes"
/>
</div>
<div class="col-md-8">
<div class="card-body">
<div style="text-align: right;">
<small style="color:#3490dc;">{{$dat->organazation}}</small> <small><i class="fa fa-calendar" style="color:#3490dc" aria-hidden="true"></i> {{ $dat->created_at->format('d/m/Y') }}</small>
</div>
<h5 class="card-title"><i class="fa fa-user-circle-o" style="color:#3490dc" aria-hidden="true"></i> {{$dat->name}}</h5>
<small><i class="fa fa-map-marker" style="color:#3490dc" aria-hidden="true"></i> {{$dat->location}}</small> | <small><i class="fa fa-phone" style="color:#3490dc" aria-hidden="true"></i>{{$dat->contact}}</small>
<hr/>
<p class="card-text">
<b>{{$dat->title}}</b>
</p>
<small style="color:#3490dc;">M{{$dat->price}}</small>
<p class="card-text">
{{$dat->message}}
</p>
</div>
</div>
</div>
</div>
<br/>
#endforeach
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Work
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_work')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/workview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('jobs')->count()}}</small> <small>Posts</small>
</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Sell
</button>
</h5>
</div>
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_sell')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/sellview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('announces')->count()}}</small> <small>Posts</small>
</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingFour">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Tenders
</button>
</h5>
</div>
<div id="collapseFour" class="collapse" aria-labelledby="headingFour" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_tender')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/tenderview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('Kinds')->count()}} </small><small>Posts</small>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br/>
#include('footer')
#endsection
My controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
use DB;
class PostController extends Controller
{
//
public function mapost()
{
$data = Auth::user()->Announce::orderBy('created_at', 'DESC')->get();
return view('users.mapost',['data'=>$data]);
}
}
My route in web.php
Route::get('users/mapost', 'PostController#mapost')->name('users.mapost');
I don`t know where I am getting this wrong, i will appreciate any help thanks in advance
Look at this line:
$data = Auth::user()->Announce::orderBy('created_at', 'DESC')->get();
Here you attempt to call the orderBy method of the Auth::user()->Announce class and of course, such class does not exist. It would make sense to do something like this:
Announce::where('user_id', $youruserid)->orderByDesc('created_at');
Tried all the possible solution to refresh the component but failed. Is there any option not to push the new comments and refresh the $comments variable whatever it contains?
Want to refresh $comments and its relation with replies in the blade on click of the send button
Calling $refresh action on the send button but it doesn't seem to work. Even tried to re-render the component with $this->render(). This also fails.
<div>
#foreach($comments as $item)
<div class="row" #if($item->reply_id != null) style="margin-left:40px;" #endif>
<div class="col-md-12">
<div class="py-md-4 py-3 border_bottom" >
<div class="row">
<div class="col-md-1 col-sm-1 col-1">
<div class="rating_person pt-3">
<img src="{{ isset($item->owner->profile_picture) ? asset($item->owner->profile_picture) : asset('images/default.jpg') }}">
</div>
</div>
<div class="col-md-11 col-sm-12 col-12">
<div class="rating_view_here_content_single_border">
<div class="rating_view_here_content_single">
<div class="rating_view_stars d-flex justify-content-between pt-3">
<div class="rating_view_heading">
<h4>{{ $item->owner->name }}</h4>
<div class="rating_wrapper">
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
<a href="#" class="grey_rating active-rating">
<i class="fa fa-star" aria-hidden="true"></i>
</a>
</div>
</div>
<span class="rating_days">{{ \App\Library\Helper::getTime($item->created_at) }}</span>
</div>
<div class="rating_comment_here pt-3">
<p>{{ $item->comment }}</p>
<p>
<a href="javascript:void(0)" class="reply" data-id="{{ $item->id }}" wire:click="toggleCommentBox({{ $item->id }}, 'true')">
<i class="fa fa-reply" aria-hidden="true"></i> <span>Reply</span>
</a>
</p>
</div>
#if($item_id == $item->id && $show=="true")
<div class="video_inner_form_wrapper commentBox-{{ $item->id }}">
<form wire:submit.prevent="sendReply" class="row">
<input type="hidden" name="reply_id" value="{{ $item->id }}">
<div class="comment_input col-md-8">
<input type="text" class="bluish_label video_inner_input #error('replyText') is-invalid #enderror" wire:model.lazy="replyText" placeholder="Write your comment here">
#error('replyText')
<div class="invalid-feedback">{{$message}}</div>
#enderror
</div>
<div class="col-md-4">
<button type="submit" class="btn_edit text-uppercase" wire:click="$refresh">Send</a>
<button type="button" class="btn_edit text-uppercase cancel" wire:click="toggleCommentBox({{ $item->id }}, 'false')">Cancel</a>
</div></form>
</div>
#endif
</div>
</div>
</div>
</div>
</div>
<livewire:frontend.discussion-chat :key="'chat-' . $item->id" :comments="$item->replies" :id="$model_id" :type="$model_type" />
</div>
</div>
#endforeach
</div>
Since none of the properties is updated, the livewire chat component will not refresh.
Possible solution is not to pass the list as a param but fetch it inside the chat component. Use events to trigger a refresh:
#click="$emit('discussion.chat.{{ $id }}.refresh')"
Inside frontend.discussion-chat have a
public function listeners(): array
{
return [
"discussion.chat.$this->id.refresh" => "reload"
];
}
public function reload(): void
{
// E.g.
$this->comments->fresh();
}
Trying to get only one condition to be true, if the first issue is proven right. The if condition is after a foreach loop. So the loop will check to see if each loop fits the criteria and give the respecive answer.
I've tried get the the information corrected using #isset and #switch.
<!-- Like a quote -->
<div>
<div>
<ul>
#auth
#if($quote->userLike->count() > 0)
#foreach($quote->userLike as $like)
#if($like->pivot->user_id == $id)
<li class="list-inline-item">
<form method="POST" action="{{route('likequote')}" class="likequote">
#csrf
<button class="btn btn-danger shadow-lg" id="savelike"><i class="fas fa-heart"></i>
</li>
#endif
#endforeach
#else
<li class="list-inline-item">
<form method="POST" action="{{route('likequote')}}" class="likequote">
#csrf
<input type="hidden" class="form-control col-md-4" name="likequote" id="likequote" value='{{$quote->id}}'>
<button type="submit" class="btn btn-primary shadow-lg " id="savelike"><i class="fas fa-heart"></button></i>
</form>
</li>
#endif
#endauth
<!-- Audio -->
<li class="list-inline-item">
<source src="{{$quote->mp3_url}}" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
</li>
</ul>
</div>
</div>
#else
I want to next tab only by button click.
This is my file aspirante.php that contains tab panel:
<div class="bs-example bs-example-tabs" role="tabpanel">
<ul id="myTab" class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Aspirante</li>
<li role="presentation">Domicilios</li>
<li role="presentation">Inform. Académica</li>
<li role="presentation">Inform. Adicional</li>
<li role="presentation">Finalizar</li>
</ul>
<br>
<div id="myTabContent" class="tab-content" >
include_once('aspiranteForm.php');
include_once('aspiranteDomicilioForm.php');
include_once('aspiranteInformacionAcademicaForm.php');
include_once('aspiranteAdicionalForm.php');
include_once('aspiranteTramiteCerrarForm.php');
</div>
<script>
$('.nav li a').click(function(e) {
e.preventDefault();
return false;
});
</script>
Example aspiranteForm:
<div role="tabpanel" class="tab-pane fade in active" id="aspirante" aria-labelledBy="aspirante-tab">
<form id="aspiranteForm" name="aspiranteForm" method="post" enctype="multipart/form-data" action="aspirante.php" >
<div class="row">
<div class="form-group col-md-12">
<button id="submitAspitante" type="submit" class="btn btn-primary">Save</button>
<button id="submitAspitante2" type="submit" class="btn btn-primary" onclick="$('li').removeClass('active');$('#domicilio-li').addClass('active');$('.nav-tabs > .active').next('li').find('a').trigger('click');">Save & Continue</button>
</div>
</div>
</form>
</div>
I want for default that all tabs are "no active", only the current tab is active.
When I clicked button submit (id="submitAspirante2") send data for post and next tab. Actually when I clicked no next tab.
Thank you.
First of all you dont need that script.
<div class="bs-example bs-example-tabs" role="tabpanel">
<ul id="myTab" class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Aspirante</li>
<li role="presentation"><a href="#domicilios-tab" aria-controls="domicilios-tab" role="tab" data-toggle="tab" aria-expanded="true" >Domicilios</a></li>
<li role="presentation"><a href="#academica-tab" aria-controls="aspirante-tab" role="tab" data-toggle="tab" aria-expanded="true" >Inform. Académica</a></li>
<li role="presentation">Inform. Adicional</li>
<li role="presentation">Finalizar</li>
</ul><br>
<div id="myTabContent" class="tab-content" >
include('aspiranteForm.php');
include('aspiranteDomicilioForm.php');
include('aspiranteInformacionAcademicaForm.php');
include('aspiranteAdicionalForm.php');
include('aspiranteTramiteCerrarForm.php');
</div>
Then your first active Forms should be like this
<div class="tab-pane fade in active" id="aspirante-tab">
<form id="aspiranteForm" name="aspiranteForm" method="post" enctype="multipart/form-data" action="aspirante.php" >
<div class="row">
<div class="form-group col-md-12">
<button id="submitAspitante" type="submit" class="btn btn-primary">Save</button>
<button id="submitAspitante2" type="submit" class="btn btn-primary" onclick="$('li').removeClass('active');$('#domicilio-li').addClass('active');$('.nav-tabs > .active').next('li').find('a').trigger('click');">Save & Continue</button>
</div>
</div>
Then the other inactive forms should be like this
<div class="tab-pane" id="domicilios-tab">
<form id="aspiranteForm" name="aspiranteForm" method="post" enctype="multipart/form-data" action="aspirante.php" >
<div class="row">
<div class="form-group col-md-12">
domicilios
<button id="submitAspitante" type="submit" class="btn btn-primary">Save</button>
<button id="submitAspitante2" type="submit" class="btn btn-primary" onclick="$('li').removeClass('active');$('#domicilio-li').addClass('active');$('.nav-tabs > .active').next('li').find('a').trigger('click');">Save & Continue</button>
</div>
</div>
More refference in here
why my modal don't appears when I clik in my link?
I do like this and I don't know where is wrong?
In my table, my Edit button is a dropdown button because I have two Entity joined in this table, so when I click in the link who edited one of my entity the modal don't appears, the page becomes fade only.
edit.html.twig
<a data-toggle="modal" href="#edit{{ fruit.id }}">
Edit
</a>
<div class="modal" id="edit{{ fruit.id }}">
{{ form_start(edit_form, { 'method' : 'post', 'action': path('fruit_edit', { 'id' : fruit.id }) }) }}
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Edit</h4>
</div>
<div class="modal-body">
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
</div>
</div>
{{ form_end(edit_form) }}
</div>
index.html.twig
<td>
<div class="dropdown">
<button class="btn btn-info dropdown-toggle btn-xs" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</button>
<ul class="dropdown-menu">
<li>{{ render(controller('AppBundle:Fruit:edit', { 'id' : fruit.id } )) }}</li>
<li>href="#">Categories</a></li>
</ul>
</div>
Controller
public function editAction(Request $request, Fruit $fruit)
{
$deleteForm = $this->createDeleteForm($fruit);
$editForm = $this->createForm('AppBundle\Form\FruitType', $fruit);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('fruit_edit', array('id' => $fruit->getId()));
}
return $this->render('fruit/edit.html.twig', array(
'fruit' => $fruit,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
Help me please to show what the problem, thanks!
You can try just move your <div class="modal" ... ></div> container outside the <ul></ul> tag:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="dropdown">
<button class="btn btn-info dropdown-toggle btn-xs" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</button>
<ul class="dropdown-menu">
<li>
<a data-toggle="modal" href="#edit5">
Edit
</a>
</li>
<li>Categories</li>
</ul>
<div class="modal" id="edit5">
<form>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Edit</h4>
</div>
<div class="modal-body">
<input>
<input type="submit" value="Edit" />
</div>
</div>
</form>
</div>
</div>
So...
edit.html.twig
<div class="modal" id="edit{{ fruit.id }}">
{{ form_start(edit_form, { 'method' : 'post', 'action': path('fruit_edit', { 'id' : fruit.id }) }) }}
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Edit</h4>
</div>
<div class="modal-body">
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
</div>
</div>
{{ form_end(edit_form) }}
</div>
index.html.twig
<td>
<div class="dropdown">
<button class="btn btn-info dropdown-toggle btn-xs" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</button>
<ul class="dropdown-menu">
<li>
<a data-toggle="modal" href="#edit{{ fruit.id }}">
Edit
</a>
</li>
<li>href="#">Categories</a></li>
</ul>
{{ render(controller('AppBundle:Fruit:edit', { 'id' : fruit.id } )) }}
</div>