Rainieren

Experience

2,010

0 Best Reply Awards

  • Member Since 3 Months Ago
  • 10 Lessons Completed
  • 0 Favorites

21st June, 2017

Rainieren left a reply on Call To Undefined Method Intervention\Image\File::delete() • 5 days ago

My Controller as it is now, It looks like this.

public function update_avatar(Request $request) {

        $this->middleware('auth');

        if ($request->hasFile('avatar')) {
            $avatar = $request->file('avatar');
            $filename = Auth::user()->username . time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)->fit(300,300)->save( public_path('/uploads/avatars/' . $filename));

            $user = Auth::user();
            $user->avatar = $filename;
            $user->save();

            //Verwijderd vorige foto
            if ($user->avatar != 'default.jpg') {
                $path = public_path('uploads'.DIRECTORY_SEPARATOR.'avatars'. DIRECTORY_SEPARATOR.Auth::user()->Avatarpath);
                if (file_exists($path)) {
                    Storage::delete($path);
                }
            }
        }

        return view('user.profile', array('user' => Auth::user()));
        //Image intervention
    }

I want to delete their previous photo because if everybody uploads a photo and their picture doesn't get deleted, my folder fills up with thousands of pictures and takes in ALOT of space. So if I can find a way to delete them, It has a big advantage.

Rainieren left a reply on Call To Undefined Method Intervention\Image\File::delete() • 5 days ago

Sorry, I have the same method for a banner also. Just change the name banner to avatar, and it will make sense.

The logic behind the delete is IF the new file is not equal to the previous file, Delete the previous file. Is that even possible to do? Because if u use the login that you said, "If the image is called something other then default.jpg then delete it". Simply says delete everything if it's not called default.jpg. If I'm correct.

Rainieren left a reply on Call To Undefined Method Intervention\Image\File::delete() • 5 days ago

There was no use statement Because I just found out that Intervention does not have a Delete method. So I tried to use Laravel's Storage delete method, Like this.

if ($user->avatar != 'default.jpg') {
                $path = public_path('uploads'.DIRECTORY_SEPARATOR.'avatars'. DIRECTORY_SEPARATOR.Auth::user()->Avatarpath);
                if (file_exists($path)) {
                    Storage::delete($path);
                }
            }

But this looks like it skips the whole if statement. Because it redirects me to the profile page like it should and changes the profile picture, but it doesn't delete the previous file.

Rainieren started a new conversation Laravel Giving A Folder Acces • 5 days ago

In laravel I have a delete method. A user has a profile picture and if the user updates their profile picture their old one gets deleted. But the delete method doesn't work and I think it has something to do with the permissions of the folder. It looks like it is not allowed to delete a file. Does someone know or is someone familiar with this problem? Thanks for your help.

This is the code I'm trying to execute. Which is giving me the error. Look at the last IF statement

public function update_banner(Request $request) {

        if ($request->hasFile('banner')) {
            $banner = $request->file('banner');
            $filename = Auth::user()->username . time() . '.' . $banner->getClientOriginalExtension();
            Image::make($banner)->fit(1050,250)->save( public_path('/uploads/banners/' . $filename));

            $user = Auth::user();
            $user->banner = $filename;
            $user->save();

    
            if ($user->banner!= 'defaultbanner.jpg') {
                $path = 'uploads/banners/';
                $lastpath = Auth::user()->Bannerpath;
                File::delete(public_path($path . $lastpath));
            }
        }

        return view('user.profile', array('user' => Auth::user()));
        //Image intervention
    }

Thanks in advance!

Rainieren started a new conversation Call To Undefined Method Intervention\Image\File::delete() • 5 days ago

I made a method which allows the user to update their profile picture. I also added a function which deletes their old profile picture if they update to a new one. But i get an error saying Call to undefined method Intervention\Image\File::delete().

What is causing this? In the code below it makes perfect sense for me. I hope you guys can help. Thanks in advance

Code: UserController.php

    public function update_avatar(Request $request) {

        $this->middleware('auth');

        if ($request->hasFile('avatar')) {
            $avatar = $request->file('avatar');
            $filename = Auth::user()->username . time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)->fit(300,300)->save( public_path('/uploads/avatars/' . $filename));

            $user = Auth::user();
            $user->avatar = $filename;
            $user->save();

            //Verwijderd vorige foto
            if ($user->avatar != 'default.jpg') {
                $path = 'uploads/avatars/';
                $lastpath = Auth::user()->Avatarpath;
                File::delete(public_path($path . $lastpath));
            }
        }

        return view('user.profile', array('user' => Auth::user()));

Route: `Route::post('{username}/profile', [email protected]_avatar');`

The form that is supposed to do this.

    <div class="row">
            <div class="col l12 m12 s12">
                <div class="card">
                    <div class="card-content">
                        <form enctype="multipart/form-data" action="profile" method="POST">
                            <input type="file" name="avatar">
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                            <input type="submit" class="pull-right btn btn-primary" value="Change profile">
                        </form>
                    </div>
                </div>
            </div>
        </div>

Changing the picture works just fine. If I reload the page the profile picture is updated but it doesn't delete the old one.

19th June, 2017

Rainieren left a reply on Error While Simply Trying To Display A View • 1 week ago

The route is inside a middleware yes, The middleware checks if the user is an Admin or not. If so then he can use the url.

Rainieren started a new conversation Error While Simply Trying To Display A View • 1 week ago

I created a view which allows the user to create a theme/post. The link to that view is in my navbar. But the problem is When I try to click the link (display the view) I get redirected to the home page without any errors whatsoever.

In the link of the navbar, i put <li><a href="{{ route('createtheme') }}"> which simply activates the route with the name "createtheme". This route is as followed: Route::get('/theme/create', [email protected]')->name('createtheme');. So this activated the create method in the ThemesController.php. Which is:

public function create()
    {
        return view('themes.create');
    }

So if I read this correctly, This is supposed to give me the right view, right? And it doesn't give me any errors so I don't know where to look.

This is the view I'm trying to display:

    @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">
                        <span class="card-title">New theme</span>
                    </div>
                </div>
                <div class="card">
                    <div class="card-content">
                        <form method="POST" action="">
                            {{ csrf_field() }}
                            <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
                            <div class="row">
                                <div class="input-field col s6 has-error form-group">
                                    <input id="title" class="form-control" type="text" name="title" placeholder="Title of topic">
                                    <label for="title" class="active">Title of theme</label><span>Titel is mandatory!</span>
                                </div>
                                <div class="file-field input-field col s6 form-group">
                                    <div class="btn cyan darken-1 disabled"><span>Attachment</span>
                                        <input id="attachement" type="file" name="attachment" class="disabled">
                                    </div>
                                    <div class="file-path-wrapper form-group">
                                        <input type="text" placeholder="geen" class="file-path validate form-control">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col s12 form-group">
                                    <textarea id="message-body" class="form-control" name="body"></textarea>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col s6">
                                    Hier komen opties om het onderwerp te sluiten of
                                    aan te geven dat het opgelost is, alleen bij bewerken
                                </div>
                                <div class="col s6">
                                    <a href="" class="btn right cyan darken-1" type="submit">Save</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @endsection

    @section('scripts')
    <script type="text/javascript" src="{{ asset('js/ckeditor/ckeditor.js') }}">
    </script>
    <script type="text/javascript" src="{{ asset('js/editor.js') }}"></script>
    <script type="text/javascript" src="{{ asset('js/blog.js') }}"></script>
    <script type="text/javascript" src="{{ asset('js/materialize.js') }}">
    </script>
    @endsection

And here are the routes that are related to this problem.


    Route::get('/theme/create', [email protected]')->name('createtheme');
    Route::post('/theme/create', [email protected]');

And of course the Store method:

    public function store(Request $request)
    {
        Theme::create($request->input()); //Dit doet hetzelfde als bovenstaande

        return redirect('/');
    }

Thanks in advance

18th June, 2017

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

@Snapey Okay, i understand it now. Sorry for asking you so much but I was just not thinking straight. Thanks for your help! It works and I got it now! thanks!

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

@Snapey You told me to.... What am I supposed to put there then.

This is literally what you told me to do. in your post with the Scenarios.

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

Now it shows the correct URL (theme/1/topics/19). but not the correct topic. Now it shows the topic with theme_id 9 and topic_id 1. Instead of the topic with theme_id 1 and topic_id 19. The link looks like this now. As you said. And it works and makes sense! {{ route('showtopic', ['theme_id'=>$theme->id, 'topic_id' => $topic->id]) }}

And my show method looks like this.

public function show($topic_id)
    {

        $topic = Topic::with('theme')->findOrFail($topic_id);

        return view('topics.topic')->withTopic($topic)->withTheme($topic->theme);

    }

I think there is something messed up between the 2 and it is something I can't see otherwise I could've fixed it myself.

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

@Snapey There is one small problem now. The url is switched up now. Its shows the topic of ffeeney which is correct. but the URL is theme/19/topics/1 instead of theme/1/topics/19. What is causing this?

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

I got it working, Thanks. I figured it out! Thank you very much!

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

I tried your way but it gave me an error as I said,

If I did it correctly. My theme and Controller looks like this if I try your way. theme.blade.php( the link)

<a href="{{ route('showtopic', $topic->id ) }}">

I changed the topic to showtopic because route 'topic' does not exist in web.php. And this is what my TopicsController looks like

public function show($topic_id)
    {

        $topic = Topic::with('theme')->findOrFail($topic_id);

        return view('topics.topic')->withTheme($topic->theme)->withTopic($topic);

    }

This is everything that you said in Scenario #2. Correct it if I'm wrong. But this gives me the error Missing required parameters for [Route: showtopic] [URI: theme/{theme_id}/topics/{topic_id}].

If I read the code this should just work and give me the correct topic (The one with theme_id 1 and topic_id 19). But it gives me the error above.

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

@Snapey This is supposed to bring the user to the single topic. Route::get('/theme/{theme_id}/topics/{topic_id}', [email protected]')->name('showtopic');

There is nothing with a theme in there except the Theme_id. but that is necessary for the URL to work right? The URL is supposed to be like.

If the user clicks on a theme with the theme_id 1. the URL is forum.dev/theme/1/topics. So far so good. The user gets an overview of every topic with the theme_id 1. If the user clicks on a topic in that overview with the (in this case) topic_id 19 the URL is supposed te be like forum.dev/theme/1/topics/19. This link works just fine no problems there. But the post doesn't show the one with topic_id 19 but instead, shows a topic with ID 1. That's the problem here.

In my case the THEME I clicked on has theme_id 1. Every topic with theme_id 1 gets displayed. So far so good. Now if I click on (In this case) the topic of "ffeeney" with the topic_id of 19. It is supposed to show the topic with the topic_id 19 right? And that's where the problem is. Instead of showing topic_id 19. It shows topic_id 1 and topic_id 1 has a theme_id of 9. Which does not make sense. I uploaded a 30-second video on youtube which visualises the problem. https://youtu.be/7UpabVE3GKU. I hope this make thing clear.

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

@Snapey What do you mean remove theme in my web.php? which route?

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

@Snapey I think I don't see this the right way as you do. I get the error Missing required parameters for [Route: showtopic] [URI: theme/{theme_id}/topics/{topic_id}]. (View: C:\xampp\htdocs\laravel\forum\resources\views\themes\theme.blade.php) If I change the link to this: <a href="{{ route('showtopic', ['topic_id' => $topic->id ]) }}". Be aware that the link is in a foreach loop. I dont know if this could affect it. But it looks like this and it works: @foreach($theme->topics as $topic) This is still in the Theme.blade.php.

My TopicsController.php looks like this. I took this from your Scenario #2.

public function show($topic_id)
    {
        $topic = Topic::with('theme')->findOrFail($topic_id); 

        return view('topics.topic')->with($topic->theme)->withTopic($topic);

    }

I know it is something I've done before on a previous project. But there it works just fine. but here it does not. Thanks for helping me by the way

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

Snapey, In your reply the case for this problem is Scenario #2, A topic belongs to a theme. BUT a theme can have many topics. The link in the theme.blade.php looks like this <a href="{{ route('showtopic', ['theme_id' => $theme->id, 'topic_id' => $topic->id ]) }}" And my show method looks like this.

public function show($topic_id)
    {
        $topic = Topic::with('theme')->findOrFail($topic_id);

        return view('topics.topic')->with($topic->theme)->withTopic($topic);

    }

But this still gives me the error Illegal offset type'. I think the URL shows just fine. Because it showshttp://forum.dev/theme/1/topics/19Which is equal toforum.dev/theme/{theme_id}/topics/{topic_id}. Because if u look at this picture http://imgur.com/a/ljQPm u can see that the topic (With the cat picture) has ID 19. That's also visible in the database: http://imgur.com/a/oFD0E`.

I honestly don't know how to explain this better since I'm not English but I'm trying. I hope this makes some things clearer.

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

Snapey, What I'm trying to do is, is that it needs to show the topic that the user clicked on but it doesn't do that. Instead, it shows a random topic. But it's the view that is supposed to show the topic also need te have the $theme variable so I can get the title of the theme were the topic is in. If u read this carefully it will make sense I hope. I can tell my explanations are not that great because no one every truly understands me. I hope this is a good explanation though

17th June, 2017

Rainieren left a reply on Laravel Not Displaying Correct Topic From Database • 1 week ago

I think i'm not thinking straight or something. But it still does the same It is supposed to show the topic of ffeeney but shows the topic of henry62. I have this in my show method now

public function show($id)
    {
        $topic = Topic::with('theme')->find($id);
        $theme = Theme::with('topics')->find($id);

        return view('topics.topic')->with('theme', $theme)->with('topic', $topic);

    }

And this is the view Topic.blade.php

@section('content')
<div class="container first-container">
    <div class="row first-row">
        <div class="col s12">
            @if(Auth::check())
            <div class="card">
                <div class="card-content clearfix">
                    <span class="card-title">{{ $theme->theme_title }} - {{ $topic->topic_title }}&nbsp;<span class="status-badge status-open">Open</span></span>
                    <a href="" class="btn blue-grey darken-4">Reply</a>
                </div>
            </div>
            @endif

            <div class="card blue-grey lighten-5">
                <div class="card-content">
                    <div class="collection">
                        <div class="collection-item row">
                            <div class="col s3">
                                <div class="avatar collection-link">
                                    <div class="row">
                                        <div class="col s3"><img src="/uploads/avatars/{{ $topic->user->avatar }}" class="circle responsive-img" style=""></div>
                                        <div class="col s9">
                                            <p class="user-name">{{ $topic->user->username }} @if($topic->user->isAdmin())<i class="material-icons verified">verified_user</i>@elseif($topic->user->isModerator())<i class="material-icons mod">supervisor_account</i>@endif </p>
                                        </div>
                                    </div>
                                    <p>{{ $topic->user->role->role_name }}</p>
                                    <p>Vanaf: {{ $topic->user->created_at }}</p>
                                    <p class="post-timestamp">Posted n: {{$topic->created_at}}</p>
                                </div>
                            </div>
                            <div class="col s9">
                                <div class="row last-row">
                                    <div class="col s12">
                                        <h6 class="title">{{ $topic->topic_title }}</h6>
                                        <p>{!! $topic->topic_text !!}</p>
                                    </div>
                                </div>
                                <div class="row last-row block-timestamp">
                                    <div class="col s6">
                                        <p class="post-timestamp">Last changed: {{ $topic->updated_at }}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card">
                <div class="card-content">
                    @foreach($topic->replies as $reply)
                    <div class="collection">
                            <div class="collection-item row">
                                <div class="col s3">
                                    <div href="" class="avatar collection-link">
                                        <div class="row">
                                            <div class="col s3"><img src="/uploads/avatars/{{ $reply->user->avatar }}" alt="" class="circle" style="width: 50px;"></div>
                                            <div class="col s9">
                                                <p class="user-name">{{ $reply->user->username }} @if($reply->user->isAdmin())<i class="material-icons verified">verified_user</i>@elseif($reply->user->isModerator())<i class="material-icons mod">supervisor_account</i>@endif</p>
                                            </div>
                                        </div>
                                        <p>{{ $reply->user->role->role_name }}</p>
                                        <p>Vanaf: {{ $reply->user->created_at }}</p>
                                        <p class="post-timestamp">Gepost op: {{ $reply->created_at }}</p>
                                    </div>
                                </div>
                                <div class="col s9">
                                    <div class="row last-row">
                                        <div class="col s12">
                                            <p>{!! $reply->reply_text !!}</p>
                                        </div>
                                    </div>
                                    <div class="row last-row block-timestamp">
                                        <div class="col s6">
                                            <p class="post-timestamp">Laatst aangepast op: {{ $reply->updated_at }}</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
                @if(Auth::check())
                    <div class="card">
                        <div class="card-content clearfix">
                            <a href="" class="btn blue-grey darken-4">Reply</a>
                        </div>
                    </div>
                @endif
        </div>
    </div>
</div>

Rainieren started a new conversation Laravel Not Displaying Correct Topic From Database • 1 week ago

My problem is the following. I'm making a forum and It doesn't show the topic that I clicked on but another topic from the database. It is supposed to show Topic 19 but it shows Topic 1. The URL is correct. but it shows the wrong topic. Also. As you can see in this GIF: http://imgur.com/a/AfmPZ if u look at the picture and the username, it gets clear what's wrong. How can I solve this? Thank you in advance.

Topic.blade.php (Shows the topic)

<div class="container first-container">
    <div class="row first-row">
        <div class="col s12">
            @if(Auth::check())
            <div class="card">
                <div class="card-content clearfix">
                    <span class="card-title">{{ $theme->theme_title }} - {{ $topic->topic_title }}&nbsp;<span class="status-badge status-open">Open</span></span>
                    <a href="" class="btn blue-grey darken-4">Reply</a>
                </div>
            </div>
            @endif

            <div class="card blue-grey lighten-5">
                <div class="card-content">
                    <div class="collection">
                        <div class="collection-item row">
                            <div class="col s3">
                                <div class="avatar collection-link">
                                    <div class="row">
                                        <div class="col s3"><img src="/uploads/avatars/{{ $topic->user->avatar }}" class="circle responsive-img" style="w"></div>
                                        <div class="col s9">
                                            <p class="user-name">{{ $topic->user->username }} @if($topic->user->isAdmin())<i class="material-icons verified">verified_user</i>@elseif($topic->user->isModerator())<i class="material-icons mod">supervisor_account</i>@endif </p>
                                        </div>
                                    </div>
                                    <p>{{ $topic->user->role->role_name }}</p>
                                    <p>Vanaf: {{ $topic->user->created_at }}</p>
                                    <p class="post-timestamp">Posted n: {{$topic->created_at}}</p>
                                </div>
                            </div>
                            <div class="col s9">
                                <div class="row last-row">
                                    <div class="col s12">
                                        <h6 class="title">{{ $topic->topic_title }}</h6>
                                        <p>{!! $topic->topic_text !!}</p>
                                    </div>
                                </div>
                                <div class="row last-row block-timestamp">
                                    <div class="col s6">
                                        <p class="post-timestamp">Last changed: {{ $topic->updated_at }}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card">
                <div class="card-content">
                    @foreach($topic->replies as $reply)
                    <div class="collection">
                            <div class="collection-item row">
                                <div class="col s3">
                                    <div href="" class="avatar collection-link">
                                        <div class="row">
                                            <div class="col s3"><img src="/uploads/avatars/{{ $reply->user->avatar }}" alt="" class="circle" style="width: 50px;"></div>
                                            <div class="col s9">
                                                <p class="user-name">{{ $reply->user->username }} @if($reply->user->isAdmin())<i class="material-icons verified">verified_user</i>@elseif($reply->user->isModerator())<i class="material-icons mod">supervisor_account</i>@endif</p>
                                            </div>
                                        </div>
                                        <p>{{ $reply->user->role->role_name }}</p>
                                        <p>Vanaf: {{ $reply->user->created_at }}</p>
                                        <p class="post-timestamp">Gepost op: {{ $reply->created_at }}</p>
                                    </div>
                                </div>
                                <div class="col s9">
                                    <div class="row last-row">
                                        <div class="col s12">
                                            <p>{!! $reply->reply_text !!}</p>
                                        </div>
                                    </div>
                                    <div class="row last-row block-timestamp">
                                        <div class="col s6">
                                            <p class="post-timestamp">Laatst aangepast op: {{ $reply->updated_at }}</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
                @if(Auth::check())
                    <div class="card">
                        <div class="card-content clearfix">
                            <a href="" class="btn blue-grey darken-4">Reply</a>
                        </div>
                    </div>
                @endif
        </div>
    </div>
</div>

Theme.blade.php (The view with the link to the topic)

<div class="col s12">
                <div class="card">
                    <div class="card-content"><span class="card-title">{{ $theme->theme_title }} - Topics</span>
                        <div class="collection">
                            @foreach($theme->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="card-title">{{ $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 }} on: {{  $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">Naam</p>
                                            <p class="center-align">Tijd</p>
                                        </div>
                                    </div>
                                </a>
                            @endforeach
                        </div>
                    </div>
                </div>
            </div>

Web.php (Routes)

Route::get('/theme/{theme_id}/topics', [email protected]')->name('showtheme');
Route::get('/theme/{theme_id}/topics/{topic_id}', [email protected]')->name('showtopic');

TopicsController.php (Show method that is supposed to show the correct topic)

{
        $topic = Topic::find($id);
        $theme = Theme::with('topics')->find($id);

        return view('topics.topic')->with('topic', $topic)->with('theme', $theme);

    }

Rainieren left a reply on Show Only Topics That Belong To Theme. • 1 week ago

Nevermind problem is solved now. Thank you

Rainieren left a reply on Show Only Topics That Belong To Theme. • 1 week ago

That makes sense, But it doesn't work. Now it says undefined relationship On model topic

Which is

class Topic extends Model
{
    protected $fillable = [
        'topic_title', 'topic_text', 'theme_id', 'user_id',
    ];

    public function user() {
        return $this->belongsTo('App\User');
    }

    public  function theme() {
        return $this->belongsTo('App\Theme');

    }

    public function replies() {
        return $this->hasMany('App\Reply');
    }
}

My theme controller looks like this now:

public function show($id)
    {
        $topics = Topic::with('topics')->find($id);
        $theme = Theme::with('theme')->find($id);

        return view('themes.theme')->with('topics', $topics)->with('theme', $theme);
    }

And my theme.blade.php

<div class="col s12">
                <div class="card">
                    <div class="card-content"><span class="card-title">{{ $theme->theme_title }} - Topics</span>
                        <div class="collection">
                            @foreach($theme->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="card-title">{{ $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 }} on: {{  $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">Naam</p>
                                            <p class="center-align">Tijd</p>
                                        </div>
                                    </div>
                                </a>
                            @endforeach
                        </div>
                    </div>
                </div>
            </div>

Rainieren left a reply on Show Only Topics That Belong To Theme. • 1 week ago

My show method after your comment looks like this:

$topics = Topic::all();
        $theme = Theme::with('topics')->find($id);

        return view('themes.theme')->with('topics', $topics)->with('theme', $theme);

It still doesn't work because i said $topics = Topic::all(); If u read the question. I'm trying to make it so that ONLY the topics show that BELONG to the theme.

Oh and my model looks like this.

class Theme extends Model
{
    protected $fillable = [
        'theme_title', 'theme_description', 'user_id',
    ];

    public function user() {
        return $this->belongsTo('App\User');
    }

    public function topics() {
        return $this->hasMany('App\Topic');
    }


}

Rainieren left a reply on Show Only Topics That Belong To Theme. • 1 week ago

The relationsships between the tables are correct that's not the issue. I was just asking How can I make it that it only shows the topics that belong to the theme.

Rainieren started a new conversation Show Only Topics That Belong To Theme. • 1 week ago

Hello, My problem is. When a user clicks on a theme, he/she needs to get redirected to a page with all the topics that belong to that theme. What I have now is that it shows ALL the topics in the database. How can I make it that it only shows the topics that belong to the theme? I know its something that I've done before but I don't quite remember

Here is the code below of all the files. Thanks you in advance ** theme.blade.php (Where its supposed to show all the topics that belong to the theme)**

<div class="col s12">
                <div class="card">
                    <div class="card-content"><span class="card-title">{{ $theme->theme_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="card-title">{{ $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 }} on: {{  $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">Naam</p>
                                            <p class="center-align">Tijd</p>
                                        </div>
                                    </div>
                                </a>
                            @endforeach
                        </div>
                    </div>
                </div>
            </div>

index.blade.php(Where the link to the list of all the topics that belong to that theme is.

<div class="container first-container">
        <div class="row">
            <div class="col s12">
                <div class="card">
                    <div class="card-content"><span class="card-title">Themes</span>
                        <div class="collection">
                            @foreach($themes as $theme)
                            <a href="{{ route('showtheme', ['theme_id' => $theme->id]) }}" class="collection-item avatar collection-link">
                                <img src="{{ asset('img/icon.png') }}" alt="" class="circle">
                                    <div class="row">
                                        <div class="col s8">
                                            <div class="row last-row">
                                                <div class="col s12">
                                                    <span class="card-title">{{ $theme->theme_title }}</span>
                                                    <p>{{ $theme->theme_description }}</p>
                                                </div>
                                            </div>
                                            <div class="row last-row">
                                                <div class="col s12 post-timestamp">Admin: {{ $theme->user->username }}</div>
                                            </div>
                                        </div>
                                            <div class="col s2">
                                                <h6 class="title center-align">Statistieken</h6>
                                                <p class="center-align">{{ $theme->topics->count() }} topic(s)</p>
                                            </div>
                                            <div class="col s2">
                                                <h6 class="title center-align">Laatste topic</h6>
                                                <p class="center-align">Basuds</p>
                                                <p class="center-align">30-12-2015 19:00</p>
                                            </div>
                                    </div>
                                </a>
                            @endforeach
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

** Web.php (routes) **

Route::get('/', [email protected]')->name('home');
Route::get('/theme/{theme_id}/topics', [email protected]')->name('showtheme');

Route::get('/theme/{theme_id}/topics/{topic_id}', [email protected]')->name('showtopic');

Route::group(['middleware' => 'App\Http\Middleware\AdminMiddleware'], function() {

    //THEMES

    Route::get('/theme/{theme_id}/edit', [email protected]')->name('edittheme');
    Route::patch('/theme/{theme_id}/edit', [email protected]')->name('updatetheme');

    Route::get('/theme/create', [email protected]')->name('createtheme');
    Route::post('/theme/create', [email protected]')->name('savetheme');

    Route::delete('/theme/{theme_id}/delete', [email protected]')->name('deletetheme');

    //TOPICS

    Route::get('/theme/{theme_id}/topics/{topic_id}/edit', [email protected]')->name('edittopic');
    Route::patch('/theme/{theme_id}/topics/{topic_id}/edit', [email protected]')->name('updatetopic');

    Route::get('/theme/{theme_id}/topics/create', [email protected]')->name('createtopic');
    Route::post('/theme/{theme_id}/topics/create', [email protected]')->name('savetopic');

    Route::delete('/theme/{theme_id}/topics/{topic_id}/delete', [email protected]')->name('deletetopic');



});

TopicsController.php(show method)

public function show($id)
    {
        $theme = Theme::find($id)->theme;
        $topic = Topic::find($id)->topic;

        return view('topics.topic')->with('theme', $theme)->with('topic', $topic);

    }

ThemesController.php(show method)

public function show($id)
    {
        $topics = Topic::all();
        $theme = Theme::find($id);

        return view('themes.theme')->with('topics', $topics)->with('theme', $theme);
    }

Rainieren left a reply on Undefined Variable: Theme • 1 week ago

I think the problem is pretty obvious. I think in the show method I need to pass in the $theme. for the link to work. But I also need to have $topic. That's the problem here, isn't it? How do I fix this then?

Rainieren left a reply on Undefined Variable: Theme • 1 week ago

This is the show method in the topicController.php http://imgur.com/a/uSZpU Is this what you're looking for?

Rainieren left a reply on Undefined Variable: Theme • 1 week ago

Rainieren started a new conversation Undefined Variable: Theme • 1 week ago

I'm trying to make this link work. /theme/{theme_id}/topics/{topic{id}. Which shows the topic with the ID 1 that's within the theme with the ID one. I don't know if I explained this correctly but you can see the problem if u look at the code. I have a foreach loop and within that loop, I'm trying to get the 'showtopic' route WITH theme_id AND topic_id. but it keeps giving me the error Undefined variable: theme. Does anyone know how to fix this?

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>

Web.php

Route::get('/', [email protected]')->name('home');
Route::get('/theme/{theme_id}/topics', [email protected]')->name('showtheme');


Route::get('/theme/{theme_id}/topics/{topic_id}', [email protected]')->name('showtopic');

// TODO: Zo maken dat de onderste 5 route alleen beschikbaar zijn voor de admin

Route::group(['middleware' => 'App\Http\Middleware\AdminMiddleware'], function() {

    //THEMES

    Route::get('/theme/{theme_id}/edit', [email protected]')->name('edittheme');
    Route::patch('/theme/{theme_id}/edit', [email protected]')->name('updatetheme');

    Route::get('/theme/create', [email protected]')->name('createtheme');
    Route::post('/theme/create', [email protected]')->name('savetheme');

    Route::delete('/theme/{theme_id}/delete', [email protected]')->name('deletetheme');

    //TOPICS

    Route::get('/theme/{theme_id}/topics/{topic_id}/edit', [email protected]')->name('edittopic');
    Route::patch('/theme/{theme_id}/topics/{topic_id}/edit', [email protected]')->name('updatetopic');

    Route::get('/theme/{theme_id}/topics/create', [email protected]')->name('createtopic');
    Route::post('/theme/{theme_id}/topics/create', [email protected]')->name('savetopic');

    Route::delete('/theme/{theme_id}/topics/{topic_id}/delete', [email protected]')->name('deletetopic');



});

Route::get('user/profile', [email protected]');
Route::post('user/profile', [email protected]_avatar');

If I wasn't clear enough or miss some code, Please inform me about it

15th June, 2017

Rainieren left a reply on Trying To Get Property Of Non-object • 1 week ago

Yeah it does, Like 18 which is the following.

<div class="col s6">

So that 'line' doesn't make any sense

Rainieren started a new conversation Trying To Get Property Of Non-object • 1 week ago

I'm making a forum and when a user clicks on a theme. he gets redirected to the topics page within the theme. The problem is, I get an error saying "Trying to get a property of non-object. Where is the problem?

ThemesController.php show method

 public function show($id)
    {
        $topics = Topic::find($id);

        return view('topics/topics')->with('topics', $topics);
    }

Topics.blade.php

<div class="collection">
                            @foreach($topics as $topic)
                                <a href="" class="collection-item avatar collection-link"><img src="https://nl.gravatar.com/userimage/51485075/2ca914e1b1db85aa54998d0b9ac68b81.jpg" alt="" class="circle">
                                    <div class="row">
                                        <div class="col s6">
                                            <div class="row last-row">
                                                <div class="col s12"><span class="title">Theme &gt; {{ $topic->topic_title }}</span>
                                                    <p>{!! str_limit($topic->topic_text, $limit = 150, $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"></p>
                                            <p class="center-align"></p>
                                        </div>
                                    </div>
                                </a>
                            @endforeach
                        </div>

And web.php

Route::get('/theme/{id}', [email protected]')->name('showtheme');

I know I did something obviously wrong but I can't figure out what. Thanks in advance

11th May, 2017

Rainieren left a reply on How To Show The Latest Post • 1 month ago

Non of all this works for me.

Rainieren left a reply on How To Show The Latest Post • 1 month ago

That doesn't do anything? I have a feeling I need to add something to my routes?

Rainieren started a new conversation How To Show The Latest Post • 1 month ago

I'm trying to display the latest post, posted on my website. I have a vague idea of how it needs to be done but I'm not 100% sure. I think I need to do something like this in my PostController.php

 public function index()
    {
        $laatstepost = Post::orderBy('created_at', 'desc')->take(1)->get();

        return View('showposts')->with('laatsteposts', $laatstepost);
    }

And then something like this in my view.

<div class="panel-body">
      <h3>{{ $laatsteposts->title }}</h3>
           <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
                            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
                            quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
                            consequat.</p>
           <a href="#" class="post-read-more">Lees meer...</a>
</div>

I don't know if I'm heading the right way or that I'm completely off track. If u guys can help me out that would be great! Thanks

Here is a screenshot of where it needs to be displayed: http://imgur.com/a/c1feW

If I miss code that is needed for this, Tell me

10th May, 2017

Rainieren left a reply on Error Registering A User • 1 month ago

This is the standard laravel register.blade.php

@extends('layouts.default')

@section('content')
<div class="container first-container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Registreer</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ route('register') }}">
                        {{ csrf_field() }}

                        <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                            <label for="name" class="col-md-4 control-label">Gebruikersnaam</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>

                                @if ($errors->has('name'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('name') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label for="email" class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Wachtwoord</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="password-confirm" class="col-md-4 control-label">Bevestig wachtwoord</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Registreer
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

Rainieren started a new conversation Error Registering A User • 1 month ago

I used the standard Laravel login system, and when I try to register a user via the form its gives me the error.


QueryException in Connection.php line 647:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'blog.user' doesn't exist (SQL: select count(*) as aggregate from `user` where `email` = [email protected])

I don't know where the problem comes from because before I was able to make users. The error says it is looking for blog.user while the table is called "Users". Can anyone help me?

9th May, 2017

Rainieren started a new conversation Internal Error: Failed To Retrieve The Default Value • 1 month ago

I'm trying to make a page where it displays all the posts from the database, But I keep getting the error:

Internal error: Failed to retrieve the default value```

I don't know where the problem is, I'm trying so solve this for days. Can anyone help me out?



`ManageController.php`

8th May, 2017

Rainieren left a reply on Internal Error: Failed To Retrieve The Default Value • 1 month ago

As i said... The error is this. ReflectionException in RouteDependencyResolverTrait.php line 57: Internal error: Failed to retrieve the default value

Rainieren left a reply on Internal Error: Failed To Retrieve The Default Value • 1 month ago

Here is my view, I don't know how to fix this.

@extends('layouts.default')

@section('content')
    <div class="container first-container">
        <h1>Beheer posts</h1>
        <div class="row btn-new-post">
            <div class="col-md-10"></div>
            <div class="col-md-1">
                <a href="{{ url('post/create') }}"><button type="button" class="btn btn-primary">Nieuwe post</button></a>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">

                    @foreach($allposts as $post)
                        <div class="panel panel-default">
                            <div class="panel-body">
                                <div class="row">
                                    <div class="col-md-10">
                                        <h1>{{ $post->title }}</h1>
                                        <p class="first-line-of-post">
                                        {!! $post->text  !!}
                                        </p>
                                    </div>
                                    <div class="col-md-1">
                                        <a href="{{ route('deletepost', ['id' => $post->id]) }}"><span class="glyphicon glyphicon-trash icon-large"></span>
                                        <span class="icon-small-text"><br> Verwijder </span></a>
                                    </div>
                                    <div class="col-md-1">
                                        <a href=""><span class="glyphicon glyphicon-pencil icon-large"></span>
                                            <span class="icon-small-text"><br> Bewerk </span></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    @endforeach

                <div class="row">
                    <div class="col-md-10"></div>
                    <div class="col-md-1">
                        <a href="{{ url('post/create') }}"><button type="button" class="btn btn-primary">Nieuwe post</button></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
@stop

Rainieren started a new conversation Internal Error: Failed To Retrieve The Default Value • 1 month ago

I'm trying to make a list of all my posts from the database with a delete button next to the post. I made routes with /post/manage. But it does not return the view. It gives me the error Internal error: Failed to retrieve the default value. Can someone tell whats causing this? If I did not provide enough information, ask me for more.

web.php

Route::group(['middleware' => 'App\Http\Middleware\AdminMiddleware'], function() {
    Route::get('/post/create', [email protected]')->name('createpost');
    Route::post('/post/create', [email protected]');

    Route::get('/post/manage', [email protected]')->name('managepost');

    Route::get('/post/manage', [email protected]')->name('deletepost');

    Route::get('/users', [email protected]')->name('manageusers');

    Route::get('/profile/username'. [email protected]')->name('profiel');
});


Route::get('/post/{id}', [email protected]')->name('showpost');

ManageController.php

public function create()
    {
        return view('post/manage');
    }


 public function show($id)
    {
        $post = Post::find($id);

        return view('post/manage')->with('post', $post);
    }

public function destroy($id)
    {
        
        $post = Post::find($id);
        $post->delete();
        return redirect('post/manage');
    }

7th May, 2017

Rainieren left a reply on Foreach Loop Posts Not Displaying Properly • 1 month ago

It works, but only on the HomeController. I tried to place the same code on the ManageController but that gives me the same error. Do you know how to fix this? This is my ManageController.php

<?php

namespace App\Http\Controllers;

use App\Post;
use Illuminate\Http\Request;

class ManageController extends Controller
{
 
    public function index()
    {
        $posts = Post::all();

        return view('post.manage')->with(['allposts' => $posts]);
    }

    public function create()
    {
        return view('post/manage');
    }

    public function store(Request $request)
    {
        //
    }


    public function show($id)
    {
        //
    }

    public function edit($id)
    {
        //
    }

    public function update(Request $request, $id)
    {
        
    }

    
    public function destroy($id)
    {

        return redirect('/');
    }
}

Rainieren left a reply on Foreach Loop Posts Not Displaying Properly • 1 month ago

Unfortunately, that does not work. it still gives me the same error $allposts not defined.

Rainieren left a reply on Foreach Loop Posts Not Displaying Properly • 1 month ago

I don't really get what you mean by your answer. I tried it but it gave me the same error as the first error, "$allposts not defined".

Rainieren left a reply on Foreach Loop Posts Not Displaying Properly • 1 month ago

Here is "PostController"

public function create()
    {
        return view('post/create');
    }

public function store(Request $request)
    {

        Post::create($request->input()); 

        return redirect('/');
    }


public function show($id)
    {
        $post = Post::find($id);

        return view('post/show')->with('post', $post);
    }

Rainieren left a reply on Foreach Loop Posts Not Displaying Properly • 1 month ago

What do you mean by "did you pass $allposts to your view?" Can you show me code what you mean? I'm a beginner with laravel and also don't know what you mean with "eager load". I looked at the example and this is what I have.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $fillable = [
      'title', 'slug', 'text', 'user_id'
    ];

    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function comments()
    {
        return $this->hasMany('App\comment');
    }
}

Rainieren started a new conversation Foreach Loop Posts Not Displaying Properly • 1 month ago

On my homepage, I have a foreach loop that displays all my posts from the database. I wanted to implement this same method on another page when I ran into an error. The foreach loop that I used is as followed

@foreach($post->comments as $comment)
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <p> {{ $comment->comment }} </p>
                            <a href="">{{ $comment->user->username }} </a>
                        </div>
                    </div>
                    @endforeach 

The code above is the original code and it works just perfectly fine. The code beneith is the code i tried to implement.

@foreach($allposts as $post)
                        <div class="panel panel-default">
                            <div class="panel-body">
                                <div class="row">
                                    <div class="col-md-10">
                                        <h1>{{ $post->title }}</h1>
                                        <p class="first-line-of-post">
                                        {!! $post->text  !!}
                                        </p>
                                    </div>
                                    <div class="col-md-1">
                                        <a href=""><span class="glyphicon glyphicon-trash icon-large"></span>
                                        <span class="icon-small-text" ><br> Verwijder </span></a>
                                    </div>
                                    <div class="col-md-1">
                                        <a href=""><a href=""><span class="glyphicon glyphicon-pencil icon-large"></span>
                                            <span class="icon-small-text"><br> Bewerk </span></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    @endforeach 

It gives me the error that "$allposts" is undefined. Can someone explain what I did wrong?

Rainieren left a reply on Delete Row With Corresponding Rows From Database On Click • 1 month ago

Every post in my database has an id (for example id = 1). The comments on that post have a post_id of 1 which is attached to the post with the id 1.

If I delete the post with the id 1. All the comments with post_id = 1, Will be deleted also. I need to do all of the above with just a press of a button. Sorry, my English is not that great. I don't know how to show u the code because it doesn't say here but If u know, tell me

Rainieren started a new conversation Delete Row With Corresponding Rows From Database On Click • 1 month ago

I need to delete a row from a table (in this case "post") with all the corresponding rows from another table (the reactions to that post), Simply by clicking on a link. I made a with a glyphicon from bootstrap, and if the user clicks on this glyphicon, the post and the reactions to that post will be deleted from the database.

I don't know how to add a picture or code to this discussion, If someone knows, tell me.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.