henryoladj

henryoladj

Member Since 2 Months Ago

Experience Points
4,170
Total
Experience

830 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.

Level 1
4,170 XP
Oct
28
3 weeks ago
Activity icon

Started a new Conversation Music Upload And Streaming Package In Laravel

I want to ask if there is a way i can develop a music upload platform like Datpiff that allows to upload and stream.

Is there any laravel package for that?

Oct
17
1 month ago
Activity icon

Replied to Using If Statement In Laravel

@sinnbeck Got this error ```Call to undefined method App\News::recentlyAdded()````

Activity icon

Started a new Conversation Using If Statement In Laravel

I have my post page and after the post subject i display something like (new) beside it.. How can i display that new icon only for recently made posts.

Code

<div class="card news-card">
    <div class="card-body">
          <h6 class="card-title"><a href="{{ route('news.show',$new->slug) }}"> {{$new->subject}} </a> <span class="badge card-span">New</span></h6>
           <p class="card-text" style="">{{ strip_tags(str_limit($new->body, 150)) }}</p>
           <span class="badge badge-pill badge-light card-badge">{{ $new->tags()->first()->name }}</span>
           <span class="badge badge-pill badge-light card-badge"> {{$new->user->name}} </span>
           <span class="badge badge-pill badge-light card-badge-float">{{ $new->created_at->format('M d, Y') }}</span>
        </div>
</div>

The New icon is the one with <span class="badge card-span">New</span> and i want to add it only to recently made posts

Activity icon

Started a new Conversation Using If Statement In Laravel

I have this code

<?php
$ogimg =  'https://naijaswift.com/image/' . $news->image
?>

Which displays the Og:image from the image uploaded by the users for a post.

I would love to display the default site image on the og:image if the user(s) does not upload any image in post.

i.e if users uploads an image called go.jpeg it loads like this on og:image: https://example.com/image/go.jpeg but if the user does not upload any image in post it should be https://example.com/image/default.jpeg

Activity icon

Started a new Conversation Trying To Save Uploaded Image With Name

On my Laravel Local Server this code works

private function storeImage($news)
    {
        if (request()->has('image')){
             $original = request()->file('image')->getClientOriginalName();

            $news->update([
                'image' =>  request()->file('image')->storeAs('uploads', $original),
            ]);

            $image = Image::make(public_path('image/'. $news->image))->resize(664, 373);
            $image->save();
        }
    }

But on my Shared Hosting Server it does not save the image or even the post into the database... Meanwhile making a post without images saves into the database

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@sinnbeck the code does not seem to work on live shared hosting server

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@sinnbeck thank you very much mate :)

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@sinnbeck i have solved it

private function storeImage($news)
    {
        if (request()->has('image')){
             $original = request()->file('image')->getClientOriginalName();

            $news->update([
                'image' =>  request()->file('image')->storeAs('uploads', $original),
            ]);

            $image = Image::make(public_path('image/'. $news->image))->resize(600, 600);
            $image->save();
        }
    }
Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@sinnbeck after doing dd($news->image); i could see this uploads/Freaky.jpeg

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@ftiersch yes i have and i am pasting the errors i am getting here

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

The upload is working though, it is just saying Image source not readable

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@sinnbeck well after doing that

private function storeImage($news)
    {
        if (request()->has('image')){
             $original = request()->file('image')->getClientOriginalName();

            $news->update([
                'image' =>  request()->file('image')->storeAs('uploads', $original),
            ]);

            

            $image = Image::make(public_path('storage/'. $news->image))->resize(600, 600);
            $image->save();
        }
    }

it is saying Image source not readable

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@sinnbeck so after doing this

 private function storeImage($news)
    {
        if (request()->has('image')){
             $original = request()->file('image')->getClientOriginalName();

            $news->update([
                'image' =>  request()->file('image')->storeAs($original),
            ]);

            

            $image = Image::make(public_path('storage/'. $news->image))->resize(600, 600);
            $image->save();
        }
    }

I got this error Too few arguments to function Illuminate\Http\UploadedFile::storeAs(), 1 passed in C:\MAMP\htdocs\main\app\Http\Controllers\NewsController.php on line 198 and at least 2 expected

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@sinnbeck i got this error Undefined variable: request

Activity icon

Replied to Trying To Get The Name Of An Uploaded Image

@sinnbeck so it will be like this?

private function storeImage($news)
    {
        if (request()->has('image')){
            $news->update([
                'image' => request()->image->store('uploads', 'public'),
            ]);

            $original = $request->file('image')->getClientOriginalName();

            $path = $request->file('image')->storeAs($original);

            $image = Image::make(public_path('storage/'. $news->image))->resize(600, 600);
            $image->save();
        }
    }
Activity icon

Started a new Conversation Trying To Get The Name Of An Uploaded Image

I am trying to get the name of an image and save it instead of saving it as laravel default hashing.

i.e if an image name is go.jpg it should save as go.jpg instead of randomly generated numbers

Here is my controller

private function storeImage($news)
    {
        if (request()->has('image')){
            $news->update([
                'image' => request()->image->store('uploads', 'public'),
            ]);

            $image = Image::make(public_path('storage/'. $news->image))->resize(600, 600);
            $image->save();
        }
    }
Oct
13
1 month ago
Activity icon

Started a new Conversation Laravel Image Upload Not Working

I am trying to upload multiple images into my database but instead it is only one image that is saving into the database, how can i correct this

if ($request->hasfile('image'))
          {
            foreach($request->file('image') as $image)
            {
                $filename = time().'.'.$image->extension();
                $location = public_path('image/'.$filename);
                Image::make($image)->resize(800, 400)->save($location);
                $data[] = $filename;
            }
            
            
         }
        
        //store

            $news->image = $filename;
            $image->image =json_encode($data);
            $news->save();

        return redirect()->route('news.index');
    }

View

<div class="form-group">
  <label for="image"><b>Select Image To Add</b></label>
  <input type="file" name="image[]" multiple>
</div>
Activity icon

Replied to Multiple Image Upload System

i still haven't figured it out

Activity icon

Replied to Multiple Image Upload System

@jlrdw any sugestion?

Activity icon

Replied to Multiple Image Upload System

@danielrubango after changing, the image did not save into database.

Activity icon

Replied to Multiple Image Upload System

Can someone please help

Controller

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

        $this->validate($request,[
            'subject'=>'required|min:10',
            'tags' => 'required',
            'body' => 'required|min:20',
            'filename' => 'sometimes',
            'filename.*' => 'file|image|mimes:jpeg,png,jpg,gif,svg|max:5000'

        ]);

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

        $this->storeImage($news);

        $news->tags()->attach($request->tags);

        
        //redirect
        return redirect()->route('news.index');
    }
 private function storeImage($news)
    {
       if (request()->has('image')) {
           
                foreach (request()->file('image') as $file) {
                $news->update([
                'image' => request()->image->store('uploads', 'public'),
            ]);
            }
        }
    }

View

<div class="form-group">
  <label for="image"><b>Select Image To Add</b></label>
  <input type="file" name="filename[]">
</div>

I get this error Array to string conversion

Activity icon

Replied to Multiple Image Upload System

Anyone with solution?

Oct
12
1 month ago
Activity icon

Replied to Multiple Image Upload System

i am getting this error

Array to string conversion
if (request()->hasFile('image')){

            request()->validate([
                'image.*' => 'file|image|max:5000',
            ]);

        }
private function storeImage($news)
    {
        if (request()->has('image')){
            foreach ($image as $file) {
                $news->update([
                'image' => request()->image->store('uploads', 'public'),
            ]);
            }
            
        }
    }
Activity icon

Replied to Multiple Image Upload System

@snapey any suggestions?

Activity icon

Replied to Multiple Image Upload System

I am talking about uploading more than one images

Activity icon

Replied to Multiple Image Upload System

Does not work

 private function storeImage($news)
    {
        if (request()->has('image')){
            foreach($image as $file){
                $name = time().'.'.$file->extension();
            $news->update([
                'image' => request()->image->store('uploads', 'public'),
            ]);

        }
        }
    }
Activity icon

Replied to Multiple Image Upload System

@fatihkececi it does not work

Activity icon

Started a new Conversation Multiple Image Upload System

I am trying to have a multiple image upload system but it is only one image that is showing after doing this

Form

<form action="{{route('news.store')}}" id="postform" method="post" enctype="multipart/form-data">
  {{csrf_field()}}
<div class="form-group">
  <label for="image"><b>Select Image To Add</b></label>
  <input type="file" name="image">
  <input type="file" name="image">
  <input type="file" name="image">
  <input type="file" name="image">
</div>
</form>

Controller

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

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

        ]);

        if (request()->hasFile('image')){

            request()->validate([
                'image' => 'file|image|max:5000',
            ]);

        }
        
        //store
        

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

        $news->tags()->attach($request->tags);

        $this->storeImage($news);


        
        //redirect
        return redirect()->route('news.index');
    }

private function storeImage($news)
    {
        if (request()->has('image')){
            $news->update([
                'image' => request()->image->store('uploads', 'public'),
            ]);
        }
    }
Activity icon

Replied to Display Ads In Between Post Paragraphs

@snapey Thank you very much mate 😊

Oct
11
1 month ago
Activity icon

Replied to Display Ads In Between Post Paragraphs

No one seems to want to help with this

Activity icon

Replied to Display Ads In Between Post Paragraphs

Yes they use p tags, how will i find the second paragraph?

Activity icon

Replied to Display Ads In Between Post Paragraphs

@sinnbeck examples of what??

Assuming This is a post

They equally urged the Executive arm of Government in Oyo state to ensure judicious use of the Agricultural loan to enable it achieve the purpose for which it is sought.

(Display Ads Here)

Hon. Isiaka Tunde representing Oyo East/ Oyo West constituency and Hon. Dele Adeola representing Iseyin/Itesiwaju state constituency also expressed their dissatisfaction on concentration on the loan to only two farm settlements within only one federal constituency.
Activity icon

Replied to Display Ads In Between Post Paragraphs

@sinnbeck Yes the body is html and it is one field in the database, the body posts appears in Paragraph, i want to display that adsense code after the 2nd paragraph.

How will i do this?

Activity icon

Replied to Display Ads In Between Post Paragraphs

@sinnbeck This is the new body and i will like to display the Adsense code after the 2nd or 3rd paragraph.

{!! $news->body !!}
                   <div class="share-botton"><p>Share This Post On:</p> <div class="addthis_inline_share_toolbox"></div></div>
                   <div style="float: none; margin:10px 0 10px 0; text-align:center;">
                       <h5 style="font-size: 12px;color: #000;">Google Ads</h5>
                       <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Ads 2 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:300px;height:250px"
     data-ad-client="ca-pub-1693830720882200"
     data-ad-slot="4954054410"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>

This {!! $news->body !!} displays the texts of the body i would love to add the adsense code inside the 2nd or 3rd paragraph

Activity icon

Started a new Conversation Display Ads In Between Post Paragraphs

I would love to display my google ads code in between my posts pagaraph, i need help with doing this.

Thanks

Oct
10
1 month ago
Activity icon

Replied to Get Latest News For Each Users

Problem Solved

Controller

 public function index(User $user)
    {
        $news=News::where('user_id',$user->username)->latest()->get();
        $news = $user->news()->latest()->paginate(15);
        return view ('profile.index', compact('news','user'));

    }
Activity icon

Started a new Conversation Get Latest News For Each Users

On my User's page i want to display each users latest news but instead it is displaying all the news from each users on a specific user's page.

Controller

public function index(User $user)
    {
        $news=News::where('user_id',$user->username)->latest()->get();
        $news= News::latest()->paginate(15);
        return view ('profile.index', compact('news','user'));

    }

View

@foreach($news as $new)
<div class="card news-card">
        <div class="card-body">
          <h6 class="card-title"><a href="{{ route('news.show',$new->slug) }}"> {{$new->subject}} </a></h6>
        </div>
</div>
  @endforeach

Route

Route::get('/user/{user}','[email protected]')->name('user_profile');
Oct
08
1 month ago
Activity icon

Replied to Trying To Redirect In Controller

@nakov

i did this in my controller

public function profileedit(User $user, News $news)
    {
        $profile = User::findorFail($id);
        if($user->id === $profile->user_id){
            abort(404);
        }
        return view('profile.edit')->with('profile',$profile);
    }

and it is taking me to 404

Oct
03
1 month ago
Activity icon

Replied to Trying To Redirect In Controller

@snapey like this?

@extends('main')
@if(Auth()->check())
@if(auth()->user()->name == $profile->name)
<?php
$title = $profile->name;
?>

@section('title', $title . "'". 's '. ' Profile Edit '. ' - ')

@section('body')

<div class="col main-content" id="main">
<div>
  <h3>Edit My Profile</h3>
  <hr>
</div>
<br>
        <div class="col-md-6">
            <form action="/profile-update/{{ $profile->id }}" Method="POST">
            {{ csrf_field() }}
            {{ method_field('PUT') }}
                <div class="form-group">
                    <label>Full Name</label>
                    <input type="text" name="name" value="{{ $profile->name }}" class="form-control">
                </div>
                <button type="submit" class="btn btn-success">Update</button>
            </form>
        </div>

@include('partials._footer')
@endsection
@endif
@endif
Activity icon

Replied to Trying To Redirect In Controller

@nakov I have this to make Auth users edit

Route::get('/profile-edit/{user}', '[email protected]')->middleware('auth');

How can i stop users who does not own the profile from editing please, because when i visit the edit url

http://localhost:8000/profile-edit/1

directly another user can edit it

Activity icon

Started a new Conversation Email Update Verification

I have an user profile and i allow users to update their details by editing their emails and full name, how can i send another email verification after they update their email please?

Activity icon

Replied to Trying To Redirect In Controller

@nakov this is the route

Route::get('/user/{user}','[email protected]')->name('user_profile');
Activity icon

Replied to Trying To Redirect In Controller

@nakov not to that same page where i edit

the edit url is http://localhost:8000/profile-edit/1

I want to take them to their profile page which is http://localhost:8000/user/jake not edit page which is http://localhost:8000/profile-edit/1

Activity icon

Started a new Conversation Trying To Redirect In Controller

I have a profile page which has url of localhost/user/jake

But after i am done editing with my Controller and i want to update

public function profileupdate(Request $request, $id)
    {
        $profile = User::find($id);
        $profile->name = $request->input('name');
        $profile->email = $request->input('email');
        $profile->update();

        return redirect('/user/{user}')->with('status', 'Updated');
    }

That takes me to 404 Not found page

how can i redirect it back to the User's page which is localhost/user/jake