Hey I'm starting with php and symfony and something goes wrong when I'm trying to use Support's getter. Here is what I'm getting when I use dd($ticket) in showTicket function
empty (php): supportChats
Here, supportChats is empty.
But if I use dump(ticket) inside the view associated, here is what I have
isNotEmpty (twig): supportChats
Here, supportchats is NOT empty.
So, my question is: how it is possible ? i really need explanations please
Here is my showTicket function
#[Security("is_granted('ROLE_USER') and user === currentUser")]
#[Route('/user/profil/{username}/ticket/{ticket_id}', name: 'user.profile.ticket', methods: ['GET|POST'])]
#[ParamConverter('ticket', class: Support::class, options: ['id' => 'ticket_id'])]
public function showTicket(Request $request, User $currentUser, Support $ticket): Response
{
return $this->render('user/index.html.twig', [
'ticket' => $ticket,
'panelTicket' => 'show', // twig
'panel' => 'tickets', // js
'formUserPassword' => $this->createForm(UserPasswordType::class)->createView(),
'formTickets' => $this->createForm(TicketType::class)->createView()
]);
}
And finally the view associated
<div class="d-flex border border-danger border-start-0 border-end-0 text-light mb-5 w-75 mx-auto">
<div style="min-width: 25%" class="d-flex flex-column border-info text-center w-25">
<div class="border-bottom border-danger">{{ ticket.user.firstname }}</div>
<div>Posté le <br> {{ ticket.createdAt|format_datetime(locale='fr') }}</div>
</div>
<div class="d-flex border-start border-danger text-break p-2 w-100">
<div class="flex-grow-1">
{{ ticket.message }}
</div>
<div class="d-flex flex-column justify-content-center">
{% if ticket.supportChats|length == 0 %}
<a class="btn btn-danger align-self-center w-100" href="#">Modifier</a>
<a data-action="{{ path('user.profile', {username: app.user.username}) }}" data-id="{{ ticket.id }}" class="submit-update submit-update-ticket btn btn-danger align-self-center w-100 mt-1" name="delete-ticket" title="Supprimer le Ticket">Supprimer</a>
{% endif %}
{{dump(ticket)}}
Retour
</div>
</div>
</div>
Related
Hello i'm using inani larapoll it's works great but in admin panel i can't see results of voting i can see only question, how many answers it have and how many vote was added i want to create custom page in admin where will be results of current vote like it is on WEB
like this
question - > why its don't working
answer1 -> don't know <- this option has 10 votes
answer2 -> because i'm doing something wrong <- this option has 100 votes
i added route
Route::get('/results', ['uses' => 'PollManagerController#results', 'as' => 'poll.results']);
pollmanager controller
public function results(Poll $poll)
{
$total = $poll->votes->count();
$results = $poll->results()->grab();
$options = collect($results)->map(function ($result) use ($total){
return (object) [
'votes' => $result['votes'],
'percent' => $total === 0 ? 0 : ($result['votes'] / $total) * 100,
'name' => $result['option']->name
];
});
$question = $poll->question;
echo view(config('larapoll_config.results') ? config('larapoll_config.results') : 'larapoll::dashboard.results', compact('options', 'question'));
}
and i copied results blade to my new blade
#if(Session::has('errors'))
<div class="alert alert-danger">
{{ session('errors') }}
</div>
#endif
#if(Session::has('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
#endif
<div class="w-80 m-auto">
<div class="font-size-14 font-medium-caps text-blue-100">{{ $question }}</div>
#foreach($options as $option)
<div class="mt-20px">
<div class="font-size-14 font-size-xs-12 text-blue-100">{{ $option->name }}</div>
<div class="w-100 d-flex justify-content-between pb-5px">
<div class="w-100 d-flex align-items-center">
<div class="w-100 bg-lighter-gray h-4px position-relative">
<div class="position-absolute top-0 bg-yellow h-4px" style='width: {{ $option->percent }}%'> </div>
</div>
</div>
<div class="font-size-14 font-size-xs-12 text-blue-100 pl-10px">{{ $option->percent }}%</div>
</div>
</div>
#endforeach
<div class="d-flex justify-content-between mt-auto pt-30px align-items-center">
<div class="d-flex">
<span class="fas fa-calendar text-light-gray pr-5px"></span>
<p class="mr-20px font-medium font-size-12 text-light-gray"></p>
</div>
<div class="d-flex align-items-center text-light-black flex-end font-base font-size-14 font-size-xs-12"></div>
</div>
</div>
but's its showing nothing... empty
I'm trying to implement a live search in my laravel application.
Following is my index function in the controller (ParticipantController.php). Here if there is no search happens, then displaying the participants by default.
public function index(Request $request)
{
if($request->ajax()){
$data = User::orderBy('id','DESC')
->WHERE('role_id','=','3')
->where('email','LIKE','%'.$request->search."%")
->paginate(12);
return view('admins.participants.index',compact('data'))
->with('i', ($request->input('page', 1) - 1) * 12 );
}
else{
$data = User::orderBy('id','DESC')->WHERE('role_id','=','3')->paginate(12);
return view('admins.participants.index',compact('data'))
->with('i', ($request->input('page', 1) - 1) * 12 );
}
}
following is my view (only included the relevant part)
<div class="row mt-5 ">
<div class="col-md-12 mb-2 text-right">
<input type="text" class="form-controller" id="search" name="search"></input>
</div>
</div>
<div class="row mt-2 participant-row">
#foreach ($data as $key => $user)
<div class="col-md-3 d-flex align-items-stretch mb-4">
<div class="white-panel w-100 ">
<div class="card p-2 ">
<div class="row no-gutters ">
<div class="col-auto my-auto">
#if(empty($user->image_id))
<img src="/propics/default-avatar.png" class="img_participant">
#else
<?php if(file_exists('propics/'.$user->image_id.'')){
echo '<img src="/propics/'.$user->image_id.'" class="img_participant">
';
}else{
echo '<img src="/propics/default-avatar.png" class="img_participant">
';
}?>
#endif
</div>
<div class="col my-auto">
<div class="card-block px-2">
<div class="text-right">
<a class="btn btn-default btn_icon" href="{{ route('participants.edit',$user->id) }}"><i class="fas fa-edit"></i></a>
{!! Form::open(['method' => 'DELETE','route' => ['participants.destroy', $user->id],'style'=>'display:inline']) !!}
{!! Form::button('<i class="fas fa-trash-alt"></i>', ['class' => 'btn btn-default btn_icon','type'=>'submit','onclick'=>'return confirm("Are you sure want to remove this User?")']) !!}
{!! Form::close() !!}
</div>
<hr>
<h4 class="card-title participant_name alas">{{ $user->first_name }} {{ $user->last_name }}</h4>
<p class="card-text participant_email alas">{{ $user->email }}</p>
</div>
</div>
</div>
</div>
</div>
</div>
#endforeach
</div>
And set my route as (web.php),
Route::resource('/admins/participants','Admin\ParticipantController');
Following is my Javascript which I included at the bottom of my view
<script type="text/javascript">
jQuery('#search').on('keyup',function(){
$value=jQuery(this).val();
$.ajax({
type : 'get',
url:"{{ route('participants.index') }}",
data:{'search':$value},
success:function(data){
jQuery('.participant-row').html(data);
}
});
})
</script>
Now the issue is when I search for something, as the result, the current code provides me a whole new view inside the old view. It loads a new view (with the menus and all) inside the target div class whichi mentioned in my javascript code.
I have this code :
{{ form_start(form, {'attr': {'class': 'form-vertical edit-form', 'id': 'new-users-form', 'data-view': 'new'}}) }}
<div class="row">
<div class="field-group col-xs-12 col-sm-4">
<div class="box box-default">
<div class="box-body " id="box-body-_easyadmin_form_design_element_0">
<div class="row">
<div class="col-xs-12 ">
<div class="form-group field-text">
{{ form_row(form.value, {'attr': {'class': 'form-control' }}) }}
</div>
</div>
<div class="col-xs-12 ">
<div class="form-group field-text">
{{ form_row(form.comment, {'attr': {'class': 'form-control' }}) }}
</div>
</div>
<div class="col-xs-12 form-actions">
<div class="form-group">
<div id="form-actions-row">
<button type="submit" class="btn btn-primary action-save pull-right">
<i class="fa fa-check"></i> {{ 'general.buttons.confirm'|trans }}
</button>
<a class="btn btn-danger pull-right action-delete" style="margin-right: 1%" title=""
href="{{ path('admin', {'entity' : 'User', 'action' : 'delete', 'id' : entity.id}) }}" target="_self">
<i class="fa fa-trash-o"></i>
{{ 'general.buttons.delete'|trans }}
</a>
<a name="list" class="btn btn-secondary pull-right" title=""
href="{{ path('admin', {'entity' : 'User', 'action' : 'list'}) }}" target="_self">
{{ 'general.buttons.back_to_liste'|trans }}
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{{ form_widget(form._token) }}
{{ form_end(form,{'render_rest': false}) }}
Add and Back links works just fine. The only problem is with delete button. When I try to delete I'm redirect to the liste of User entity whitout delete the current User. I don't have any errors. Please help me. Thx in advance
I'm making a discussion forum app with laravel and i face this error:
Trying to get property of non-object (View:
C:\xampp\htdocs\fourm\resources\views\discussion\show.blade.php) at
PhpEngine->evaluatePath('C:\xampp\htdocs\fourm\storage\framework\views/a2f2c494b8859e0552bfa22c40ceb4065b2efbe5.php',
array('__env' => object(Factory), 'app' => object(Application),
'channels' => object(Collection), 'errors' => object(ViewErrorBag),
'd' => null, 'best_answer' => null))in CompilerEngine.php (line 59)
This is my controller code:
public function show($slug)
{
$discussion = Discussion::where('slug', $slug)->first();
$best_answer = Reply::where('best_answer', 1)->first();
return view('discussion.show')->with('d', $discussion)->with('best_answer', $best_answer);
}
This is my view code:
#extends('layouts.app')
#section('content')
<div class="panel panel-default">
<div class="panel-heading">
<img src="{{ $d->user->avatar }}" alt="" width="40px" height="40px">
<span>{{ $d->user->name }}, <b>( {{ $d->user->points }} )</b></span>
#if($d->is_being_watch_by_user())
unwatch
#else
watch
#endif
</div>
<div class="panel-body">
<h4 class="text-center">
<b>{{ $d->title }}</b>
</h4>
<hr>
<p class="text-center">
{{ $d->content }}
</p>
<hr>
#if($best_answer)
<div class="text-center" style="padding: 40px;">
<h3 class="text-center">BEST ANSWER</h3>
<div class="panel panel-success">
<div class="panel-heading">
<img src="{{ $best_answer->user->avatar }}" alt="" width="40px" height="40px">
<span>{{ $best_answer->user->name }} <b>( {{ $best_answer->user->points }} )</b></span>
</div>
<div class="panel-body">
{{ $best_answer->content }}
</div>
</div>
</div>
#endif
</div>
<div class="panel-footer">
<span>
{{ $d->replies->count() }} Replies
</span>
{{ $d->channel->title }}
</div>
</div>
#foreach($d->replies as $r)
<div class="panel panel-default">
<div class="panel-heading">
<img src="{{ $r->user->avatar }}" alt="" width="40px" height="40px">
<span>{{ $r->user->name }} <b>( {{ $r->user->points }} )</b></span>
#if(!$best_answer)
#if(Auth::id() == $d->user->id)
Mark as best answer
#endif
#endif
</div>
<div class="panel-body">
<p class="text-center">
{{ $r->content }}
</p>
</div>
<div class="panel-footer">
#if($r->is_liked_by_user())
Unlike <span class="badge">{{ $r->likes->count() }}</span>
#else
Like <span class="badge">{{ $r->likes->count() }}</span>
#endif
</div>
</div>
#endforeach
<div class="panel panel-default">
<div class="panel-body">
#if(Auth::check())
<form action="{{ route('discussion.reply', ['id' => $d->id ]) }}" method="post">
{{ csrf_field() }}
<div class="form-group">
<label for="reply">Leave a reply...</label>
<textarea name="reply" id="reply" cols="30" rows="10" class="form-control"></textarea>
</div>
<div class="form-group">
<button class="btn pull-right">Leave a reply</button>
</div>
</form>
#else
<div class="text-center">
<h2>Sign in to leave a reply</h2>
</div>
#endif
</div>
</div>
#endsection
You're getting this error because both queries return null:
$discussion = Discussion::where('slug', $slug)->first();
$best_answer = Reply::where('best_answer', 1)->first();
So, you need to check for empty result manually with is_null() or empty() or just:
if (!$discussion) {
abort(404);
}
Or use findOrFail() to throw an exception if no record found.
You are trying to access property with null objects, and that's why you got the error like "Trying to get property of null object".
As per our discussion in comments, you are getting null values in both queries and that's the reason for error!
Try to add if..else condition like below:
if (!$d) {
session()->flash('error', 'Discussion not found.');
return redirect()->back();
} else {
return view('discussion.show')->with('d', $discussion)->with('best_answer', $best_answer);
}
Hope this helps you!
Make sure you're not returning an object and accessing it as an array. It can be a common error.
I solved mine by adding: <?php error_reporting(0);?> on page where i got error. :D
I keep getting the following error:
Missing required parameters for [Route: showtopic] [URI: theme/{id}/topics/{id}].
This is what my Web.php looks like:
Everything regarding topics in web.php
Route::get('/theme/{id}/topics/{id}', 'TopicsController#show')->name('showtopic');
Route::get('/theme/{id}/topics/{id}/edit', 'TopicsController#edit')->name('edittopic');
Route::patch('/theme/{id}/topics/{id}/edit', 'TopicsController#update')->name('updatetopic');
Route::get('/theme/{id}/topics/create', 'TopicsController#create')->name('createtopic');
Route::post('/theme/{id}/topics/create', 'TopicsController#save')->name('savetopic');
Route::delete('/theme/{id}/topics/{id}/delete', 'TopicsController#destroy')->name('deletetopic');
Everything regarding themes in web.php
Route::get('/theme/{id}/topics', 'ThemesController#show')->name('showtheme');
Route::get('/theme/{id}/edit', 'ThemesController#edit')->name('edittheme');
Route::patch('/theme/{id}/edit', 'ThemesController#update')->name('updatetheme');
Route::get('/theme/create', 'ThemesController#create')->name('createtheme');
Route::post('/theme/create', 'ThemesController#save')->name('savetheme');
Route::delete('/theme/{id}/delete', 'ThemesController#destroy')->name('deletetheme');
I put every route regarding this topic in this question. So when I click on the link in my view:
<a href="{{ route('showtopic', ['id' => $topic->id]) }}"
I keep getting the error that I showed in the beginning of this question
I hope I made this clear enough for you to understand. Please inform me if I miss information that is needed in this question. Thanks in advance
Theme.blade.php
<div class="col s12">
<div class="card">
<div class="card-content"><span class="card-title"> - Topics</span>
<div class="collection">
#foreach($topics as $topic)
<a href="{{ route('showtopic', ['theme_id' => $theme->id, 'topic_id' => $topic->id]) }}" class="collection-item avatar collection-link"><img src="/uploads/avatars/{{ $topic->user->avatar }}" alt="" class="circle">
<div class="row">
<div class="col s6">
<div class="row last-row">
<div class="col s12"><span class="title">Theme - {{ $topic->topic_title }}</span>
<p>{!! str_limit($topic->topic_text, $limit = 125, $end = '...') !!}</p>
</div>
</div>
<div class="row last-row">
<div class="col s12 post-timestamp">Posted by: {{ $topic->user->username }} op: {{ $topic->created_at }}</div>
</div>
</div>
<div class="col s2">
<h6 class="title center-align">Replies</h6>
<p class="center replies">{{ $topic->replies->count() }}</p>
</div>
<div class="col s2">
<h6 class="title center-align">Status</h6>
<div class="status-wrapper center-align"><span class="status-badge status-open">open</span></div>
</div>
<div class="col s2">
<h6 class="title center-align">Last reply</h6>
<p class="center-align"></p>
<p class="center-align">Tijd</p>
</div>
</div>
</a>
#endforeach
</div>
</div>
You have to give two different parameters name for your route parameter as
Route::get('/theme/{theme-id}/topics/{topic-id}', 'TopicsController#show')->name('showtopic');
and then pass the both parameters as
{{ route('showtopic', ['theme-id' => $theme->id, 'topic-id' => $topic->id]) }}
If you want to call your route with only one parameter, then make the second parameter as option in your route as
Route::get('/theme/{theme-id}/topics/{topic-id?}', 'TopicsController#show')->name('showtopic');
and then pass the both parameters as
{{ route('showtopic', ['theme-id' => $theme->id]) }}
To use the route() helper, rename id to:
Route::get('/theme/{themeId}/topics/{topicId}', 'TopicsController#show')->name('showtopic');
And because this route has two parameters, you need to pass both parameters:
{{ route('showtopic', ['themeId' => $theme->id, 'topicId' => $topic->id]) }}