Rainieren

Experience

5,190

0 Best Reply Awards

  • Member Since 7 Months Ago
  • 33 Lessons Completed
  • 0 Favorites

15th October, 2017

Rainieren started a new conversation Adding Birthday To Register Form • 3 days ago

Hello, I'm making a register form and I added 2 new inputs already, But I have one more issue and that is a birthday. I need an input that only accepts birthdays and after registration inserts them into the database. I have no clue how to make this input and how to add the birthday table in the user migration. My project user migration looks like this

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('role_id')->unsigned()->default(1);
            $table->string('first_name');
            $table->string('last_name');
            $table->string('username');
            $table->string('email')->unique();
            $table->string('avatar')->default('default.jpg');
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

I will spare you the long registerform.blade but I know how to insert it all into the database, The only thing I don't know is how to add the table to the user migration and how to add an input that only accepts birthdays. Maybe something like a bootstrap date picker. Thanks in advance

Rainieren left a reply on Laravel Bootstrap 4 Implementation • 3 days ago

@tisuchi I don't quite understand what the article says. I don't know what to do. Can you maybe give me some instructions? I think you're right about the laravel mix thing, I am running laravel 5.5 I believe. In my previous project, it worked perfectly fine like this.

Rainieren started a new conversation Laravel Bootstrap 4 Implementation • 3 days ago

Hello, I was testing something with a new laravel project and I'm trying to make bootstrap 4 work. I added every link to the files in my app.blade.php like this


<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="{{ asset('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css') }}" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{{ asset('css/bootstrap.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('css/bootstrap.min.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('css/font-awesome.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('css/app.css') }}">

And like this

<script src="{{ asset('js/app.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/jquery-3.2.1.min.js') }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script type="text/javascript" src="{{ asset('js/bootstrap.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/bootstrap.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/app.js') }}"></script>

but it still uses the regular bootstrap 3 that laravel uses as standard. I don't get why it isnt working. Tips are welcome

Rainieren left a reply on Pusher Errors Specifying Cluster • 3 days ago

Of course, I specified my cluster it is just not working. This is the link to the tutorial: https://www.youtube.com/watch?v=iiBcOKYxd0Q&t=709s

Rainieren started a new conversation Pusher Errors Specifying Cluster • 3 days ago

Hello, I'm following a tutorial on how to make a chatroom and I keep getting errors in my console about me not specifying my cluster. I've looked on the internet for a couple hours now looking for the solution but I can't find it. This is what it shows Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":4001,"message":"Did you forget to specify the cluster when creating the Pusher instance? App key 5C5dsCds78d82D829 does not exist in this cluster."}}}

It just keeps giving me errors like this.

14th October, 2017

Rainieren left a reply on Laravel Real Time Chat App • 4 days ago

@davy_gy I'm looking for a tutorial that is using a similar setup like mine. A system that makes a logged in user, able to send a message to another user by clicking on their name and sending them a message. I haven't found any tutorial yet that is using that concept. As you can see in the GIF in my previous reply, On the side of that system I got a list of people. A user gets added to this list if he/she pressed a button which says "Send message" on his/her profile. If the logged in user clicks on one of these users, he/she is able to talk with the person in real time. Also, All the tutorials I have seen so far are using the same styles and HTML for all messages and I can't figure out how to separate the styles for a sent message and a received message. I just haven't found a tutorial that is using that concept and that's exactly what i'm looking for

Rainieren left a reply on Laravel Real Time Chat App • 4 days ago

@tisuchi So the tutorial that you provided can help me on my way of making my system work?

Rainieren left a reply on Laravel Real Time Chat App • 4 days ago

@tisuchi I did but they are using one HTML file for the messages. I want to be able to style them differently, For instance, The messages I send need to be blue and on the right side while the ones that I receive are grey and on the left side. And it needs to be for every user. I haven't found any tutorials yet that have that system. They're all just on top of each other and the same style.

Rainieren left a reply on Laravel Real Time Chat App • 4 days ago

@davy_yg I think you can see it in the image that I provided. A user needs to be able to send another user a message. And then that user will be on the side of the message system. If they click on it they will be able to talk to them. Here is a small GIF to make it clear https://imgur.com/a/SYwNy

Rainieren started a new conversation Laravel Real Time Chat App • 4 days ago

Hello, I'm currently making the front end of a messaging system. And as of the front-end, it's going quite well as you can see in this screenshot: https://imgur.com/a/HdLqZ Here for I want to ask you guys if u know a great tutorial to make this. I, unfortunately, have no experience in making that whatsoever. I can use some great advice.

My problem with all the tutorials I have found so far was that all the message styles were the same. and you couldn't distinguish them from each other. A great example of this is, for instance, Facebook Messenger. The sender's messages are blue while the receivers messages are grey. This means if I send a message it would be blue for me and the message that the person receives would be grey for him. This is also the other way around. I already made the entire HTML and CSS. now I just need to find the perfect tutorial that I can wrap my front-end around. Any suggestion? If ur willing to help with this project I would be open for that as well!

Rainier laan.

19th July, 2017

Rainieren started a new conversation Error If The User Is Not Logged In. • 2 months ago

I have a website where I check if a user is equal to a certain username, In this case, the user name of the reply. Basically, it just checks if the user that is logged in is equal to a comment's username If so they can do this. But the problem is is if a user is not signed in. It gives me an error with Trying to get property of non-object. Is there another way to check this so that it works even when the user is not logged in?

This is the IF-statement I talked about, I have multiple of these throughout the view

@if(Auth::user()->username == $reply->user->username)
                                                    <a href="{{ route('deletereply', ['id' => $reply->id]) }}"  class="waves-effect waves-light btn button-xs-danger right"
                                                       onclick="event.preventDefault(); document.getElementById('delete-form{{ $reply->id }}').submit();">Delete
                                                        <form id="delete-form{{ $reply->id }}"
                                                        action="{{ route('deletereply', ['id' => $reply->id]) }}"
                                                        method="POST"
                                                        style="display: none">
                                                        {{ csrf_field() }}
                                                        {{ method_field('DELETE') }}
                                                        </form>
                                                    </a>
                                                <a  class="waves-effect waves-light btn button-xs-neutral right">Edit</a>
                                            @endif

Thanks in advance!

Rainieren left a reply on Error While Updated To Last PHPStorm Version • 2 months ago

That does the exact same thing as I did, It doesn't do anything. Still gives me the same error

Rainieren left a reply on Error While Updated To Last PHPStorm Version • 2 months ago

Same thing, The problem is is in the if statement as i said.

Rainieren left a reply on Error While Updated To Last PHPStorm Version • 2 months ago

Nothing, It's the end of a div.... @Parasoul

Rainieren left a reply on Error While Updated To Last PHPStorm Version • 2 months ago

I'm not logged in but it still should be able to show the page but just without the buttons sinse the user is not logged in.

Rainieren left a reply on Error While Updated To Last PHPStorm Version • 2 months ago

The problem is in the Auth verification. I have multiple IF statements which determine if a user belongs to that post or not by using something like this:

@if(Auth::user()->username == $reply->user->username)

@endif

Before the update, it worked perfectly but now it does not. If I comment all the if statement in my view the site works fine

Rainieren left a reply on Error While Updated To Last PHPStorm Version • 2 months ago

No, Line 41 is just a HTML line which is this <div class="row last-row block-timestamp">. De relations are just fine. I don't get why this happened because i didn't change anything and it worked perfectly 2 days ago

Rainieren started a new conversation Error While Updated To Last PHPStorm Version • 2 months ago

Hello, My website worked just fine, But when I updated my PHPStorm to the last version it suddenly gave me an error. The error states as followed Trying to get property of non-object (View: C:\xampp\htdocs\laravel\forum\resources\views\topics\topic.blade.php)

I don't know what it is because before the update everything worked perfectly. Also, the button with the class submit is now grey? Maybe that has something to do with it?

Here is Topic.blade.php

@extends('layouts.default')

@section('content')
<div class="container first-container">
    <div class="row first-row">
        <div class="col s12">
            <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>
                </div>
            </div>
            <div class="card blue-grey lighten-5">
                <div class="card-content">
                    <div class="collection">
                        <div class="collection-item row">
                            <div class="col s3" style="padding-bottom: 20px;">
                                <div class="avatar collection-link">
                                    <div class="row">
                                        <div class="col s3">
                                            <a href="{{ route('showprofile', ['username' => $topic->user->username ]) }}">
                                                <img src="{{ asset('uploads/avatars/' . $topic->user->avatar) }}" class="circle responsive-img" style="">
                                            </a>
                                        </div>
                                        <div class="col s9">
                                            <p class="user-name">{{ $topic->user->username }}</p>
                                        </div>
                                    </div>
                                    <p>Role: {{ $topic->user->role->role_name }}</p>
                                    <p>Member since: {{ $topic->user->created_at }}</p>
                                    <p class="post-timestamp">Posted: {{$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->diffForHumans() }}</p>
                                    </div>
                                    <div class="col s6">
                                        @if(Auth::user()->username == $topic->user->username || Auth::user()->role_id == 2)
                                            <p class="post-timestamp right">
                                                <a href="{{ route('deletetopic', ['id' => $topic->id]) }}"
                                                   onclick="event.preventDefault(); document.getElementById('delete-form{{ $topic->id }}').submit();">delete
                                                    <form id="delete-form{{ $topic->id }}"
                                                          action="{{ route('deletetopic', ['id' => $topic->id]) }}"
                                                          method="POST"
                                                          style="display: none">
                                                        {{ csrf_field() }}
                                                        {{ method_field('DELETE') }}
                                                    </form>
                                                </a>
                                            </p>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            @if(Auth::guest())

            @else
            <div class="card">
                <div class="card-content">
                    <span class="card-title">Leave a Reply</span>
                    <div class="row">
                        <form method="POST" action="{{ route('createreply') }}">
                            {{ csrf_field() }}
                            <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
                            <input type="hidden" name="topic_id" value="{{ $topic->id }}">
                            <div class="col s1">
                                <img src="/uploads/avatars/{{ Auth::user()->avatar }}" class="" style="height: 64px;width: 64px;position: relative;top: 15px;">
                            </div>
                            <div class="form-group col s11 input-field comment-form-bubble">
                                <textarea id="message-body textarea1" class="form-control" rows="10" name="reply_text" placeholder="Got something to say?" style="height: 5rem; padding-left: 5px;"></textarea>
                            </div>
                            <div class="col s12 offset-s1">
                                <button class="btn blue right" type="submit"><i class="material-icons right">reply</i>Reply</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            @endif

            <div class="card">
                <div class="card-content">
                    <p>Comments • {{ $topic->replies->count() }}</p>
                    @foreach($topic->replies->sortByDesc('created_at') as $reply)
                    <div class="collection" style="border: none;">
                            <div class="collection-item row" >
                                <div class="col s3" style="padding-bottom: 20px;">
                                    <div href="" class="avatar collection-link">
                                        <div class="row">
                                            <div class="col s3"><a href="{{ route('showprofile', ['username' => $reply->user->username ]) }}">
                                                    <img src="{{ asset('uploads/avatars/' . $reply->user->avatar) }}" alt="" class="" style="width: 50px;">
                                                </a>
                                            </div>
                                            <div class="col s9">
                                                <p class="user-name">{{ $reply->user->username }}</p>
                                            </div>
                                        </div>
                                        <p>Role: {{ $reply->user->role->role_name }}</p>
                                        <p>Posted: {{ $reply->created_at->diffForHumans() }}</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">
                                            <a href=""><small style="font-size: 14px; color: grey">Reply</small></a>
                                        </div>
                                        <div class="col s6">
                                            @if(Auth::user()->username == $reply->user->username)
                                                <small style="font-size: 14px; color: red; margin-left: 10px;" class="right">
                                                    <a href="{{ route('deletereply', ['id' => $reply->id]) }}" style="color: red;"
                                                       onclick="event.preventDefault(); document.getElementById('delete-form{{ $reply->id }}').submit();">Delete
                                                        <form id="delete-form{{ $reply->id }}"
                                                        action="{{ route('deletereply', ['id' => $reply->id]) }}"
                                                        method="POST"
                                                        style="display: none">
                                                        {{ csrf_field() }}
                                                        {{ method_field('DELETE') }}
                                                        </form>
                                                    </a>
                                                </small>
                                                <small style="font-size: 14px; color: cornflowerblue" class="right">Edit</small>
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    @endforeach

                    @if($topic->replies->count() == 0 )
                            <h5 style="font-style: italic; color: grey" >No Replies yet</h5>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>


@endsection

In the error it says this:

in d2de93f86c5533060cc20907e5fb47a8b04b8bc9.php line 41
at CompilerEngine->handleViewException(object(ErrorException), 1) in PhpEngine.php line 44
at PhpEngine->evaluatePath('C:\\xampp\\htdocs\\laravel\\forum\\storage\\framework\\views/d2de93f86c5533060cc20907e5fb47a8b04b8bc9.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'topic' => object(Topic), 'theme' => object(Theme))) in CompilerEngine.php line 59
at CompilerEngine->get('C:\\xampp\\htdocs\\laravel\\forum\\resources\\views/topics/topic.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'topic' => object(Topic), 'theme' => object(Theme))) in View.php line 137
at View->getContents() in View.php line 120

Maybe you guys can help me out? Thanks in advance!

13th July, 2017

Rainieren left a reply on PHPstorm Not VueJS Friendly? • 3 months ago

@bashy No, It still gives me a whole lot of errors, By the way, how did you put a photo there?

Rainieren started a new conversation PHPstorm Not VueJS Friendly? • 3 months ago

I have VueJS installed in my file in PHPstorm but it looks like this. http://imgur.com/a/l545K All kind of errors and warnings but it still works. I installed the VueJS plugin for PHPstorm but that doesn't work. Is this normal? This really frustrates me because there are no actual errors

Rainieren left a reply on Laravel Make:auth Call To Undefined Function Get() • 3 months ago

Nevermind i fixed it already

Rainieren started a new conversation Laravel Make:auth Call To Undefined Function Get() • 3 months ago

Hello, I'm following the tutorial "Let's build a forum with laravel" And when I try to do "Php artisan make: auth" i get this error [Symfony\Component\Debug\Exception\FatalThrowableError] Call to undefined function get()

What is causing this? I don't know where the problem is so I don't know what code to post.

Thanks in advance

12th July, 2017

Rainieren started a new conversation Laravel Feedback When Leaving Comment • 3 months ago

Hello, Is there a way so the user gets a better feedback when leaving a comment on something. I have a system right now where if the user leaves a reply, he/she gets redirected to the top of the page and that is not really user-friendly because the user needs to scroll down to view their comment. Is there a way so the user stays or gets directed to his/her comment?

11th July, 2017

Rainieren left a reply on Laravel Delete All With Relation? • 3 months ago

For me, it doesn't because I'm not that familiar with foreign keys? I thought I could just do this in the destroy method using some similar code that I was already using. but I guess that is a no go? I'll try to figure it out if its the only option?

Rainieren left a reply on Laravel Delete All With Relation? • 3 months ago

I looked at that one @rob897 and if I read it correctly he just wants to delete 2 things related to each other, I'm trying to delete 3 things related to each other, A theme, All the topics within that theme and all the replies to all those topics.

Rainieren left a reply on Laravel Delete All With Relation? • 3 months ago

@rob897 I don't quite understand what ur saying. My database is correct. Can you maybe explain or show me what u man?

Rainieren started a new conversation Laravel Delete All With Relation? • 3 months ago

Hello, I'm trying to figure out how I can delete everything that is connected to a theme, Currently, I have a topic which has replies and to delete those 2 from the database I do something like this in the destroy method

$topic = Topic::find($id);

$topic->replies()->delete();

$topic->delete();

return redirect('/');

But a topic is within a theme. So what I'm trying to do is, add a function which allows the user to delete a theme, But that function also needs to delete ALL the topics within that theme and then ALL the replies of all those topics.

I maybe figured that it needs to look something like this but I can be completely wrong.

$theme = Theme::find($id);
$theme->topics()->replies->delete();
$theme->delete();

return redirect('/')

The relations between all the things are okay but I can list them here, A theme has many Topics A Topic has many replies

How do I do this? Thanks in advance

PS: Sorry for the weird title, I don't know how to explain this (Tips always appreciated)

10th July, 2017

Rainieren started a new conversation Laravel Submitting A Form By Pressing Enter • 3 months ago

I made a couple of forms which allowed the user to press a button and the form gets submitted. Is there a way to submit a form by pressing the Enter key? I currently have a simple form which is this.

<div class="card">
                <div class="card-content">
                    <span class="card-title">Leave a Reply</span>
                    <div class="row">
                        <form method="POST" action="{{ route('createreply') }}">
                            {{ csrf_field() }}
                            <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
                            <input type="hidden" name="topic_id" value="{{ $topic->id }}">
                            <div class="form-group col s12 input-field">
                                <i class="material-icons prefix">mode_edit</i>
                                <textarea id="message-body textarea1" class="form-control materialize-textarea" name="reply_text" placeholder="Type your reply"></textarea>
                            </div>
                            <div class="col s12">
                                <button class="btn right blue-grey darken-4" type="submit"><i class="material-icons right">reply</i>Reply</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

Is this possible to do?

Rainieren started a new conversation Call To Undefined Relationship [topic] On Model [App\Theme]. • 3 months ago

I'm trying to display the latest Topic that is related to a Theme. I did this before and I tried the following code in the ThemesController (Index method, Sinse it's the homepage),

$topics = Theme::with('topic', 'lastTopic.user')->get();
$themes = Theme::all();

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

And the method I'm calling is this.

public function lastTopic()
    {
        return $this->hasOne(Topic::class)->latest();
    }

The method sits inside the Theme Model. So what is causing this issue? This is for my homepage so the route is this Route::get('/', '[email protected]')->name('home');. I know it is something I've done before but I can't figure it out. Thanks in advance

7th July, 2017

Rainieren left a reply on Laravel Get Latest Reply From Topic • 3 months ago

But @Demers94 The problem is now If a topic has no replies it gives me Trying to get property of non-object Which makes sense to me since there is not yet a reply left. Can I do something with an if statement that detects if a comment has been left, show the latest one? If not, Show some other text?

Rainieren started a new conversation Laravel Get Latest Reply From Topic • 3 months ago

Hello, I'm trying to display the latest post's username and date. I used something similar by using. Something along the lines of {{ topic->replies->sortBydesc('id')->first->user->username}} It makes sense to me. I also used something like $Allreplies which I defined in the controller with $allposts = Reply::all(); but that gets me ALL the replies of the entire forum and that's not what I want, It needs to display the latest reply of that particular topic.

Can someone tell me how to do this? My Controller looks like this

public function show($id)
    {

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

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

21st June, 2017

Rainieren left a reply on Call To Undefined Method Intervention\Image\File::delete() • 3 months 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() • 3 months 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() • 3 months 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 • 3 months 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() • 3 months 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 • 3 months 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 • 3 months 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 • 4 months 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 • 4 months 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 • 4 months 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 • 4 months 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 • 4 months 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 • 4 months 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 • 4 months 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 • 4 months 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 • 4 months 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 • 4 months 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 • 4 months 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

Edit Your Profile
Update

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