mohamedhamidi

mohamedhamidi

Member Since 2 Years Ago

Experience Points
4,950
Total
Experience

50 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
43
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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,950 XP
Jul
07
3 days ago
Activity icon

Awarded Best Reply on Laravel Public_html Files Fail To Load In Shared Hosting

Apparently the problem was in those files permission , i set it to 755 for folders and 644 for files and everything worked like charm

Activity icon

Replied to Laravel Public_html Files Fail To Load In Shared Hosting

Apparently the problem was in those files permission , i set it to 755 for folders and 644 for files and everything worked like charm

Activity icon

Started a new Conversation Laravel Public_html Files Fail To Load In Shared Hosting

My laravel (v5.8) project works fine in localhost , but after i uploaded it to cpanel all images and css and JS files in public html failed to load in the browser and show errors in browser console like :

"Failed to load our-approach.png:1 resource: the server responded with a status of 404 ()" "Failed to load resource: the main.css:1 server responded with a status of 500 ()"

While the framework itself loaded fine and show no errors. I updated php to 7.4 and followed almost every youtube and articles and nothing worked.

index.php modified :

     require __DIR__.'/../laravel/vendor/autoload.php';

     $app = require_once __DIR__.'/../laravel/bootstrap/app.php';

AppServiceProvider.php modified :

        public function register()
        {

           $this -> app -> bind('path.public', function()
           {
                return base_path('public_html');
           });

        }

My project structure in cpanel :

|-- bin 

|-- cache 

|-- laravel (project files without the public folder) 

       |-- app

       |-- bootstrap

       |-- config

       .env

        server.php

        ... and the rest of the files

|-- etc 

|-- logs 

|-- mail 

|-- public_html

       |-- css 

       |-- js 

       |-- img

       .htaccess

       index.php

       ...rest of files
Jul
01
1 week ago
Activity icon

Replied to Split A Page Into Multiple Pages Using Pagination

That worked like charm , i edited the code like that and it worked , thank you so much @snapey

Old code :

// Code

$bodyParts = str_split($post->body, 2000);

//Code

Better solution :

// Code

$bodyParts = explode("==break here==", $post->body);

//Code
Activity icon

Replied to Split A Page Into Multiple Pages Using Pagination

That's what i am actually working on right now , if you got some ideas about the logic behind to fix that, your help would be appreciated

Activity icon

Replied to Split A Page Into Multiple Pages Using Pagination

a) The body output in browser is html in paragraph tag and could style it with css

b) I post articles from admin panel , it's the owner of the website who's authorized to post articles and apparently wouldn't inject script tags

Activity icon

Replied to Split A Page Into Multiple Pages Using Pagination

Following your instructions i finally got the final solution , thanks man and sorry :D

post show function in Controller :

public function show(Post $post)
{
	
  $items = array();

  // split whole body into 2000 characters each parts

  $bodyParts = str_split($post->body, 2000);

  // iterate through the parts and fill the array

  foreach($bodyParts as $bodyPart)
  {
    array_push($items, $bodyPart);
  }

 // get current page for Paginator
  $currentPage = LengthAwarePaginator::resolveCurrentPage();
 // indicate number of parts to show per page
  $perPage = 1;

  $currentItems = array_slice($items, $perPage * ($currentPage - 1), $perPage);

  $paginator = new LengthAwarePaginator($currentItems, count($items), $perPage, $currentPage);

  $results = $paginator->appends('filter', request('filter'));

  $results->withPath($post->slug);


return view('blog.show', compact('post','results'));

}

And then in the show view :

  <div class="post-body mb-5">
    @foreach($results as $part)
      <p>{!! nl2br($part) !!}</p>
    @endforeach
{!! $results->links() !!}
  </div>
Jun
30
1 week ago
Activity icon

Replied to Split A Page Into Multiple Pages Using Pagination

What i want to paginate is the body_html , sometimes it's too long to show in single page , also it's better SEO practice to split articles into 3 pages. The problem is that the body is only one entity retrieved to the view , not multiples bodies

Activity icon

Replied to Split A Page Into Multiple Pages Using Pagination

Of course i read the documentation 4 times before asking here , you didn't get my question, usual pagination is used when retrieving data from multiple rows in database , but what i want to paginate is the body which is only one instance but sometimes it is too long to display in one page

Activity icon

Started a new Conversation Split A Page Into Multiple Pages Using Pagination

I am making a blog , in the blog.show.blade view sometimes the body is too long and want to divide it into parts and add 'previous' , 'next' buttons , but the problem is that the body is stored all in one column in database so how can i paginate it ?

show.blade.php (the article show view) :

    @if($post->image_url)
    <div class="post-image">
      <img class="mb-5" src="{{ $post->image_url }}" alt="{{ $post->slug }}">
    </div>
    @endif

    <div class="post-title">
      <h1 class="mb-4" >{{ $post->title }}</h1>
    </div>


  <div class="post-body mb-5">
    {!! $post->body_html !!}
  </div>
  </div>
</div>
Jun
28
1 week ago
Activity icon

Awarded Best Reply on Fails To Rename Image Before Upload Using StoreAs

I solved it ! Apparently there was no need to storeAs() method at all , the new code is like below :

  if ($request->hasFile('image')) {
      $image = $request->file('image');
      $fileName = $request->slug.'.' .$image->getClientOriginalExtension();

      $destination = $this->uploadPath;

      $successUploaded = $image->move($destination, $fileName);
Activity icon

Replied to Fails To Rename Image Before Upload Using StoreAs

I solved it ! Apparently there was no need to storeAs() method at all , the new code is like below :

  if ($request->hasFile('image')) {
      $image = $request->file('image');
      $fileName = $request->slug.'.' .$image->getClientOriginalExtension();

      $destination = $this->uploadPath;

      $successUploaded = $image->move($destination, $fileName);
Activity icon

Started a new Conversation Fails To Rename Image Before Upload Using StoreAs

I created a form to store article with an image , and generate a resized version as thumbnail from it.

I want the image to be renamed after the article slug and stored in the "public/img/articles-images " directory but i keep receiving : "Image source not readable" error

This is the article upload handler function in my controller :

    private function handleRequest($request)
   {
  	$data = $request->all();
  	if ($request->hasFile('image')) {
     	$image = $request->file('image');
      	$fileName = $request->slug;

      		
      $successUploaded = $image->storeAs('img/articles-images', $fileName);

      if($successUploaded) {
        $width = config('cms.image.thumbnail.width');
        $height = config('cms.image.thumbnail.height');

   $extension = $image->getClientOriginalExtension();
   $thumbnail = str_replace(".{$extension}", "_thumb.{$extension}", $fileName);

        Image::make('img/articles-images' . '/' . $fileName)
         	->resize($width, $height)
         	->save('img/articles-images' . '/' . $thumbnail);
   }

      $data['image'] = $fileName;
  }

  return $data;
}
Jun
23
2 weeks ago
Activity icon

Replied to Route Group Prefix With Two Parameters Returns Error

I didn't expect the solution is just that , excuse my amateur skills in laravel , thank you so much bro that worked as charm !

Activity icon

Started a new Conversation Route Group Prefix With Two Parameters Returns Error

I am making a multi language blog , I prefix the URL with the selected language like localhost/en/category-name , but i keep receiving error like : " Argument 1 passed to Illuminate\Routing\RouteFileRegistrar::{closure}() must be an instance of App\Category, string given, called in /var/www/html/Blog/vendor/laravel/framework/src/Illuminate/Routing/Route.php on line 205 "

My route page is as follows :

	Route::group(['prefix' => '{language}'], function() {

	Route::get('/{category}', function(Category $category) {

	$locale = ucfirst(app()->getLocale());
	$posts = $category->posts()
									->where('lang', $locale)
									->with('author','tags','comments')
									->latestFirst()
									->published()
									->paginate(2);

		$categories = Category::with(['posts' => function($query) {
									$query->published();
						 }])->orderBy('title', 'asc')->get();

	return view('blog.postsCategories.latestArticles', ['heading' => $category->title], 		compact('posts','categories'));

	})->name('latestArticles');


	});

My Lang middleware is as follows :

public function handle($request, Closure $next)
{
    \App::setLocale($request->language);

    return $next($request);
}

My View is as follows :

    @foreach($categories as $category)
      <div class="card mb-3 item border-0">
        <div class="row no-gutters">
          <div class="d-flex align-items-center col-md-8">
            <div class="card-body">
              <h5 class="card-title"><a href="{{ route('latestArticles', [app()->getLocale() ,$category->slug]) }}">{{ $category->title }}</a></h5>
            </div>
          </div>
          <div class="d-flex justify-content-center col-md-4">
            <img src="/img/landing-page/{{$category->slug}}.png" class="card-img" alt="{{$category->slug}}">
          </div>
        </div>
       </div>
    @endforeach