henryoladj

henryoladj

Member Since 1 Week Ago

Experience Points 2,000
Experience Level 1

3,000 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

14 Sep
1 day ago

henryoladj left a reply on Unique Slug Duplicate Entry

@snapey it works fine now just that it still displays posts with same ID and slug 5 times...

henryoladj left a reply on Unique Slug Duplicate Entry

@snapey my Model is called News, but i am getting this error Undefined variable: news

from this line

$previous = News::where('slug',Str::slug($news->subject))->count();

henryoladj left a reply on Unique Slug Duplicate Entry

@snapey I moved it to my controller

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

        $this->validate($request,[
            'subject'=>'required|min:10',
            'tags' => 'required',
            'body' => 'required|min:20'

        ]);
        
        //store
        $news=auth()->user()->news()->create($request->all());

        $news->tags()->attach($request->tags);
        $news->slug = Str::slug($news->subject);
        $news->slug = Str::slug($news->subject).'-'.$news->id;
        $news->save();
        //redirect
        return redirect()->route('news.index');
    }

The initial post appears once with an ID but if i try to duplicate it then it appears twice with another ID

E.g First Post (localhost:8000/post/new-post-1) Second Post (localhost:8000/new-post-2) this one appears twice.

How can i resolve?

henryoladj left a reply on Unique Slug Duplicate Entry

@snapey

 protected static function boot() {
    parent::boot();

    static::created(function($news){
        $news->slug = Str::slug($news->subject).'-'.$news->id;
    $news->save();
    });
    }

This is actually making the posts appear more than once, how can i resolve this?

henryoladj left a reply on Unique Slug Duplicate Entry

@snapey Is it possible the ID does not show for the initial post and show only for the duplicate post?

henryoladj left a reply on Unique Slug Duplicate Entry

@snapey

 protected static function boot() {
    parent::boot();

    static::creating(function ($news) {
        $news->slug = Str::slug($news->subject);
        
    });

    static::created(function($news){
        $news->slug = Str::slug($news->subject).'-'.$news->id->save();
    });
    }

Just like this?

henryoladj left a reply on Unique Slug Duplicate Entry

Model News.php

protected static function boot() {
    parent::boot();

    static::creating(function ($news, $slug=null) {
        $news->slug = Str::slug($news->subject).'-'.$news->id;
        
    });
    }

It is still saying duplicate entry after doing this

henryoladj left a reply on Unique Slug Duplicate Entry

I did this $news->slug = Str::slug($news->subject->'{id}');

and it is giving me error

13 Sep
2 days ago

henryoladj started a new conversation Unique Slug Duplicate Entry

On my website i have a slug which is unique, but once users try to post same news it shows this error Integrity constraint violation: 1062 Duplicate entry.

Please how can i resolve this by saying post already made or by adding the slug url with an id of the news at the back i.e localhost:8000/post/welcome-to-my-post-1 if the ID of the post is 1

Thanks

henryoladj started a new conversation Laravel Registration Confirmation

I am looking to deploying my laravel project soon and i will love to add email confirmation after users register, i will love to know if anyone can share me a link or videos on how to that.

Thanks in advance

11 Sep
4 days ago

henryoladj left a reply on Meta Tags And Other Seo Features

What if the contents on each pages are different. you can not just add them. You need to specify.

How can you do that?

10 Sep
5 days ago

henryoladj started a new conversation Meta Tags And Other Seo Features

I want to add meta tags like Open Graph taking the post title and link and Twitter Card to my laravel project, does anyone have idea on how i can?

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

@snapey yes i have... Immediately i click on the login button, i just get undefined variable but it shows well on all other pages

Blade

@guest
   Welcome, Guest
     <br>
     <b>Stats:</b> {{$sum}}  Members, {{$total}} Topics
     <br>
     <b>Date:</b> {{ now()->format('l, d F Y \a\t h:i A')}}
     <br>
     <b><li><a href="{{ route('login')}}">Login</a></li></b> |
        @if (Route::has('register'))
          <li><a href="{{ route('register') }}">Register</a></li>
        @endif

       @else
Welcome, <a href="{{route('user_profile',auth()->user())}}">{{ Auth::user()->name }}</a> 
       <br>
       <b>Stats:</b>  Members,  Topics
       <br>
      <b>Date:</b> {{ now()->format('l, d F Y \a\t h:i A')}}
      <br>
      <br>
<a class="dropdown-item" href="{{ route('logout') }}"onclick="event.preventDefault(); document.getElementById('logout-form').submit();"> {{ __('Logout') }}</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST">
@csrf
</form>
@endguest

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

Will i need to do something to the LoginController?

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

So i got it to work on every views and controller but it did not work for log in.

It shows undefined variable total when i click the login link

PostController

public function index(Request $request)
    {
       $news= News::latest()->paginate(15);
       $users = User::latest();
       $totalNews = News::count();
       $totalUsers = User::count(); 
        return view('pages.welcome',compact('news', 'tags', 'users'))->with(['total'=>$totalNews])->with(['sum'=>$totalUsers]);
    }

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

@sti3bas throws Undefined variable: totalUsers when i am about to login or view posts

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

@snapey throws error when i am about to login and view posts

henryoladj left a reply on Trying To Get Tags Associated To A Post

Still having problems with it.

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

The thing is that i am trying to get the total result of all the users and the total result of all the news made.

I have my PostController which is the Homepage i have NewsController for the news

PostController.php

public function index(Request $request)
    {
       $news= News::latest()->paginate(15);
       $users = User::latest();
       $totalNews = News::count();
       $totalUsers = User::count(); 
        return view('pages.welcome',compact('news', 'tags', 'users', 'totalNews', 'totalUsers'));
    }

NewsController.php

public function index(Request $request, $tag=null)
    {   
        if($tag){
            $tag=Tag::where('name',$tag)->first();
            $news=$tag->news()->latest()->paginate(15);
        }else{
            $news= News::latest()->paginate(15);
        }
        $totalNews = News::count();
        $totalUsers = User::count();
        return view('categories.news',compact(['news','tag','totalNews', 'totalUsers']));
    }

Web.php

Route::resource('/', 'PostController');

// Route::resource('/category', 'NewsController');
Route::resource('/news', 'NewsController');

Someone should please help

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

I really wish someone could help me one this please

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

It is also showing same error if i want to check some posts. But it is showing on the home page and category page.

henryoladj left a reply on Problem With Getting Total Number Of Users And News From Database

It is giving error as i want to login Undefined variable: totalUsers

I am thinking i need to add it to the login controller?

henryoladj started a new conversation Problem With Getting Total Number Of Users And News From Database

I have my database which consists of users tables and news tables.

I would love to get the total number of users and news. and put them on a controller and display it on my view.

NewsController.php

public function index(Request $request, $tag=null)
    {   
        if($tag){
            $tag=Tag::where('name',$tag)->first();
            $news=$tag->news()->latest()->paginate(15);
        }else{
            $news= News::latest()->paginate(15);
        }
        $news = News::withCount('news')->get();
        return view('categories.news',compact(['news','tag']));
    }

PostController.php

public function index(Request $request)
    {
       $news= News::latest()->paginate(15);
       $users = User::latest();
        return view('pages.welcome',compact('news', 'tags', 'users'));
    }
09 Sep
6 days ago

henryoladj left a reply on Trying To Get Tags Associated To A Post

@snapey Got this Invalid argument supplied for foreach()

henryoladj left a reply on Trying To Get Tags Associated To A Post

Can anyone help with this.

henryoladj left a reply on How To Get Total Number Of Posts Made By All Users

Also when i move on each category the total posts changes

public function index(Request $request, $tag=null)
    {   
        if($tag){
            $tag=Tag::where('name',$tag)->first();
            $news=$tag->news()->latest()->paginate(15);
        }else{
            $news= News::latest()->paginate(15);
            
        }
        $users = User::Count();
        return view('categories.news',compact(['news','tag', 'users']));
    }

henryoladj left a reply on How To Get Total Number Of Posts Made By All Users

So it worked showing the total numbers of users and also total numbers of posts

But immediately i click log in i get this Undefined variable: users

Code

@guest
                                            Welcome, Guest
                                            <br>
                                            <b>Stats:</b> {{$users->count()}} Members, {{$news->count()}}  Topics
                                            <br>
                                            <b>Date:</b> {{ now()->format('l, d F Y \a\t h:i A')}}
                                            <br>
                                            <b><li><a href="{{ route('login') }}">Login</a></li></b> |
                                            @if (Route::has('register'))
                                            <li><a href="{{ route('register') }}">Register</a></li>
                                            @endif

                                            @else
                                            Welcome, <a href="{{route('user_profile',auth()->user())}}">{{ Auth::user()->name }}</a> 
                                            <br>
                                            <b>Stats:</b> {{$users->count()}} Members, {{$news->count()}} Topics
                                            <br>
                                            <b>Date:</b> {{ now()->format('l, d F Y \a\t h:i A')}}
                                            <br>
                                            <br>

Controller

public function index(Request $request)
    {
       $news= News::latest()->paginate(15);
       $users = User::latest();
        return view('pages.welcome',compact('news', 'tags', 'users'));
    }

henryoladj left a reply on How To Get Total Number Of Posts Made By All Users

@snapey could you please help with this.

Thanks

henryoladj left a reply on Trying To Get Tags Associated To A Post

@snapey It works now but how can i pass it in a link?

<a href="{{route('news.index', ['tag'=>$news->tags()->first()->url])}}">[ {{ implode(', ', $news->tags()->pluck('name')->toArray() ?? [] )}} ]</a>

henryoladj left a reply on Trying To Get Tags Associated To A Post

Does anyone have solution to this please?

henryoladj left a reply on How To Get Total Number Of Posts Made By All Users

Still waiting for help on this Please.

henryoladj left a reply on How To Get Total Number Of Posts Made By All Users

PostController

public function index(Request $request)
    {
       $news=News::with(['id' => function($query) {
        return $query->latest()->paginate(2);
        }])->Count('id')->get();
        return view('pages.welcome',compact('news', 'id'));
    }

Post.php

public function post()
    {
        return $this->belongsTo(Post::class);
    }

News.php

public function news()
    {
        return $this->belongsTo(News::class);
    }

henryoladj left a reply on I Want To Display Latest Posts On My Laravel Home Page

i have changed the whole Controller code to

 $news= News::latest()->paginate(15);

and it works

henryoladj left a reply on I Want To Display Latest Posts On My Laravel Home Page

@munazzil it is not displaying the post according to the latest using the above code you wrote

henryoladj left a reply on Trying To Get Tags Associated To A Post

@snapey yeah i have some items with not tags.

still getting this error implode(): Invalid arguments passed

henryoladj started a new conversation How To Get Total Number Of Posts Made By All Users

Controller.php

public function index(Request $request)
    {
       
        if($request->has('tags')){
            $tag=Tag::find($request->tags);
            $news=$tag->news;
        }else{
        $news = News::with(['post as post_count' => function($query) {
        return $query->latest()->limit(5)->paginate(15);
        }])->get(); 
        }
        return view('pages.welcome',compact('news', 'tags'));
    }

Then i tried displaying it with this

{{$news->post_count}}

It is not showing any number

henryoladj started a new conversation I Want To Display Latest Posts On My Laravel Home Page

Controller.php

public function index(Request $request)
    {
       
        if($request->has('tags')){
            $tag=Tag::find($request->tags);
            $news=$tag->news;
        }else{
        $news = News::with(['post' => function($query) {
        return $query->latest()->limit(5)->paginate(15);
        }])->get(); 
        }
        return view('pages.welcome',compact('news', 'tags'));
    }

I want the post lists to be displayed according to the latest posts made.

henryoladj left a reply on Trying To Get Tags Associated To A Post

@snapey yet another error Call to a member function implode() on null after trying this

{{ $news->tags->implode('name',', ') }}
08 Sep
1 week ago

henryoladj left a reply on Trying To Get Tags Associated To A Post

@snapey another error implode(): Invalid arguments passed

henryoladj left a reply on Trying To Get Tags Associated To A Post

@snapey the problem is that i am getting htmlspecialchars() expects parameter 1 to be string, array given after using

{{ explode(', ', $news->tags()->pluck('name')) }}

henryoladj left a reply on Trying To Get Tags Associated To A Post

@snapey Yeah true, but what can i change it to so that it can show the two or more tags?

my code

{{ $news->tags()->first()->name }}

henryoladj left a reply on Send Some Routes In Laravel To Custom 404 Page

@jlrdw When i visit http://localhost:8000/category i see some posts, how can i send it to 404 instead of showing those posts?

henryoladj left a reply on Trying To Get Tags Associated To A Post

@snapey I selected more than tags for a post and after posting it, it is only one tag that is showing related to the post

henryoladj left a reply on Send Some Routes In Laravel To Custom 404 Page

But how can i send some routes to 404?

henryoladj started a new conversation Send Some Routes In Laravel To Custom 404 Page

I have some links on my website that i want to create 404 page for. How can i achieve this e.g if user visits this url http://localhost:8000/category/ i want to send them to a custom 404 page.

07 Sep
1 week ago

henryoladj left a reply on Error When Trying To Make Category Title Show

When i am trying to delete i get this error Undefined variable: tag

Controller.php

public function destroy(News $news)
    {   
        if(auth()->user()->id !== $news->user_id){
            abort(401, "Please Login");
        }
        $news->delete();
        $news= News::paginate(15);
        return view('categories.news', compact('news'));
    }
public function index(Request $request, $tag=null)
    {   
        if($tag){
            $tag=Tag::where('name',$tag)->first();
            $news=$tag->news()->paginate(15);
        }else{
            $news= News::paginate(15);
        }
        return view('categories.news',compact(['news','tag']));
    }