I'm making a forum and the if the user clicks on a theme, he gets redirected to the page where all the topics are that belong to that theme. What I'm trying to do, is that the user is able to click on the topic and gets redirected to it.
The problem is, is that I get an error saying Undefined variable: theme
As you can see in the code below, I have a foreach loop in my theme.blade.php which loops all the topics that belong to the theme he/she clicked on. In the beginning of the loop there is a <a href="{{ route('showtopic', ['theme_id' => $theme->id, 'topic_id' => $topic->id]) }}"1 which is supposed to bring the user to the topic that he/she clicked on. The URL that is supposed to show is forum.dev/theme/{theme_id}/topics/{topic_id} But that doesn't work.
And it gives me that error code. All the code is below, If i miss some code, Please inform me about it and i'll update the 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>
</div>
</div>
Web.php
Route::get('/', 'ThemesController#index')->name('home');
Route::get('/theme/{theme_id}/topics', 'ThemesController#show')->name('showtheme');
Route::get('/theme/{theme_id}/topics/{topic_id}', 'TopicsController#topic')->name('showtopic');
Route::group(['middleware' => 'App\Http\Middleware\AdminMiddleware'], function() {
//THEMES
Route::get('/theme/{theme_id}/edit', 'ThemesController#edit')->name('edittheme');
Route::patch('/theme/{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/{theme_id}/delete', 'ThemesController#destroy')->name('deletetheme');
//TOPICS
Route::get('/theme/{theme_id}/topics/{topic_id}/edit', 'TopicsController#edit')->name('edittopic');
Route::patch('/theme/{theme_id}/topics/{topic_id}/edit', 'TopicsController#update')->name('updatetopic');
Route::get('/theme/{theme_id}/topics/create', 'TopicsController#create')->name('createtopic');
Route::post('/theme/{theme_id}/topics/create', 'TopicsController#save')->name('savetopic');
Route::delete('/theme/{theme_id}/topics/{topic_id}/delete', 'TopicsController#destroy')->name('deletetopic');
});
Route::get('user/profile', 'UserController#profile')->name('showprofile');
Route::post('user/profile', 'UserController#update_avatar');
TopicsController.php (Show method)
public function show($id)
{
$theme = Theme::find($id);
$topics = Topic::find($id);
return view('topics/topic')->with('topics', $topics)->with('theme', $theme);
}
I don't know if you can use the double '->with' option.
What will work is the following:
return view('topics/topic', ['topics' => $topics, 'theme'=> $theme]);
You pass an array as the second argument of the view. You can add as many keys and variables as you like.
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
im newbie about statamic,
im try to solve this code :
<div class="container">
<div class="intro">
<div class="row">
<div class="col-md-12">
<h2 class="title-uppercase text-white">{{ section_three_title }}</h2>
<div class="row-project-box row">
{{ relate:section_three_categories }}
{{ entries }}
<div class="col-project-box col-sm-6 col-md-4 col-lg-3">
<a href="{{ url }}" class="project-box">
<div class="project-box-inner">
<h5>{{ title }}</h5>
</div>
</a>
</div>
{{ /entries }}
{{ /relate:section_three_categories }}
</div>
view all projects <i class="icon icon-chevron-right"></i>
</div>
</div>
</div>
</div>
the code provide this :
i want to align these box
direzionale operativo dirigenziale not in horizonatal but in vertical like this:
direzionale
operativo
dirigenziale
i think that is a bootstrap configuration but i dont know about the statamic world
anyone can help me ?
thanks a lot
The problem here seems that you are using responsive breakpoints on your columns,
so if you want to set the boxes one below the other all the times you have to set the .col-project-box always be full-width adding this class col-12 and set the .row-project-box horizontal alignment center adding this class justify-content-center to it.
<div class="container">
<div class="intro">
<div class="row">
<div class="col-md-12">
<h2 class="title-uppercase text-white">{{ section_three_title }}</h2>
<div class="row-project-box row justify-content-center">
{{ relate:section_three_categories }}
{{ entries }}
<div class="col-project-box col-12">
<a href="{{ url }}" class="project-box">
<div class="project-box-inner">
<h5>{{ title }}</h5>
</div>
</a>
</div>
{{ /entries }}
{{ /relate:section_three_categories }}
</div>
view all projects <i class="icon icon-chevron-right"></i>
</div>
</div>
</div>
Am trying to display all the data on the admin end but i have failed. How
can i display it?
This is the method that i want to display all the data(Workflows):
public function getUserWorkflows(){
$user = $this->userRepo->users();
$active_module = AppConstants::$ACTIVE_MOD_USERS;
$appraisals = Appraisal::with(
['academicBackgrounds','keyDuties','additionalAssignments',
'competences','workflow', 'assignments','keyDuties'] )->
where('user_id','=',$user->id)->orderBy('created_at','desc')->get();
$summaries = DataGenerator::getAppraisalSummaries($appraisals);
$user = User::with(['department'])->find($user->id);
$appraisalsAssigned = DataGenerator::getAssingedAppraisals($user->id);
$assignedSummaries = DataGenerator::getAppraisalSummaries($appraisalsAssigned);
return view('user.tasks',compact('appraisals','users','active_module','summaries','appraisalsAssigned','assignedSummaries'));
}
Below is the code snippet from the view where i want the data to displayed. But it has totally failed to display. Because i think there is something that am not getting right:
<div class="col s12">
<div class="col s12">
<ul id="issues-collection" class="collection">
<li class="collection-item avatar">
<i class="material-icons circle blue darken-4">folder</i>
<span class="collection-header">Workflow</span>
</li>
#if(isset($appraisals) && count($appraisals) > 0)
#foreach($appraisals as $appraisal)
#if($loop->iteration <= 3)
<li class="collection-item">
<div class="row row-custom-modal-footer collections-title">
<div class="col s12"><strong>{{$loop->iteration}}. </strong>
{{str_replace('_',' ',$appraisal->document_name)}}</div>
</div>
<div class="row row-custom-modal-footer valign-wrapper">
<div class="col s3"><p>Date: <span class="text-primary">{{$appraisal->created_at}}</span></p></div>
<div class="col s5">
<span class="task-cat blue-stepper">
#if(isset($summaries))
#foreach($summaries as $summary)
#if($summary['id'] == $appraisal->id)
{{$summary['stage']}}
#endif
#endforeach
#endif
</span>
</div>
<div class="col s2">
<div class="progress">
<div class="determinate blue darken-4"
#if(isset($summaries))
#foreach($summaries as $summary)
#if($summary['id'] == $appraisal->id)
style="width: {{$summary['percentage']}};"
#endif
#endforeach
#endif></div>
</div>
</div>
<div class="col s1">
<p class=" camel-case"><a class="text-primary bold-text" href="{{route('view_appraisal',[$appraisal->id])}}">View</a></p>
</div>
<div class="col s1">
<p class=" camel-case"><a class="text-primary bold-text" href="{{route('view_appraisal',[$appraisal->id])}}">Stop Workflow</a></p>
</div>
</div>
</li>
#endif
#endforeach
<li class="collection-item">
<div class="row">
<div class="col s12 spacer-top">
View all your tasks
</div>
</div>
</li>
#else
<li class="collection-item">
<div class="col s12 bold-text">
<p>There are no pending tasks</p>
</div>
</li>
#endif
</ul>
</div>
</div>
I want when the person logs in as an admin, they are able to see all the data from the database once they access the view. But it only displays the data when the person logs in as a user.
I have found the solution hence i just needed to make these edits in my controller method:
public function getUserWorkflows(){
$user = $this->userRepo->users();
$active_module = AppConstants::$ACTIVE_MOD_USERS;
// Edited this line of code
$appraisals = Appraisal::with(
['academicBackgrounds','keyDuties','additionalAssignments',
'competences','workflow', 'assignments','keyDuties'] )->
orderBy('created_at','desc')->get();
$summaries = DataGenerator::getAppraisalSummaries($appraisals);
$user = User::with(['department'])->find($user->id);
$appraisalsAssigned = DataGenerator::getAssingedAppraisals($user->id);
$assignedSummaries = DataGenerator::getAppraisalSummaries($appraisalsAssigned);
return view('user.tasks',compact('appraisals','users','active_module','summaries','appraisalsAssigned','assignedSummaries'));
}
Thanks so much, i have found the solution after carefully going through the controller method's lines of code
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]) }}
I am making a forum and when the user clicks on a theme, a page shows up with every topic that belongs to that theme. The problem is, how do I do this?
I made a for each loop which shows ALL the topics from the database instead of the topics that belong to that theme I clicked on. How can I do this?
Web.php
Route::get('/', 'ThemesController#index')->name('home');
Route::get('/theme/{id}', 'ThemesController#show')->name('showtheme');
ThemesController.php
I only show the show method because I believe that's the only one necessary here
public function show($id)
{
$topics = Topic::all($);
return view('themes/topics')->with('topics', $topics);
}
topics.blade.php
#extends('layouts.default')
#section('content')
<div class="container main-content">
<div class="row first-row">
<div class="col s12">
<div class="card">
<div class="card-content clearfix">Nieuw topic</div>
</div>
</div>
<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="" 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 = 100, $end = '...') !!}</p>
</div>
</div>
<div class="row last-row">
<div class="col s12 post-timestamp">Gepost door: {{ $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">Laatste reply</h6>
<p class="center-align">Naam</p>
<p class="center-align">Tijd</p>
</div>
</div>
</a>
#endforeach
</div>
</div>
</div>
</div>
<div class="col s12">
<div class="card">
<div class="card-content clearfix">Nieuw topic</div>
</div>
</div>
</div>
</div>
#endsection
I believe I'm doing something obviously wrong but I can't see what.
Help will be appreciated. Thanks in advance
If I miss some code, Please inform me.
How are you defining the relationship between a theme and it's topics? You'll have to have something like a one to many or many to many established in your database for you to be able to query correctly. Do you have anything like that yet?
****edit****
public function show($id)
{
$topics = Theme::find($id)->topics;
return view('themes/topics')->with('topics', $topics);
}