lararocks

lararocks

Member Since 3 Years Ago

Experience Points 3,030
Experience Level 1

1,970 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 1
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.

12 Jun
1 month ago

lararocks started a new conversation Return Function Result To Caller And Then Do Some Tasks In The Background

Hello there,

I'm developing a mobile app that posts some data and images via Laravel API endpoint.

The thing is the function takes time until it saves the post and write the images to the disk before it returns the result to the mobile app and shows the thank you message.

Is there a way where I can make my Laravel function saves the post, returns the post ID, and then continue writing images to disk so I can reduce the time the user waits for the thank you message?

Thanks

28 Mar
3 months ago

lararocks started a new conversation Laravel Downloads A File Instead Of Viewing The Site

Hello,

My Laravel site works perfectly on localhost. Now as I uploaded it to shared hosting, when I try to access the site, it downloads a file named "download" rather than displaying the site.

I made sure I set the right php version on the server, and all folder permissions seem to be correct.

Any idea?

15 Mar
4 months ago

lararocks left a reply on Public Folder Downloads Php File Instead Of Rendering Them

It was a folder permission issue. Thanks

lararocks left a reply on Public Folder Downloads Php File Instead Of Rendering Them

@JLRDW - It didn't work actually. The issue seems not to be with the index file.

Even this gives a 500 internal server error mysitename.com/public/temp.php

But mysitename.com/test.php still works

Even mysitename.com/temp/temp.php works

lararocks started a new conversation Public Folder Downloads Php File Instead Of Rendering Them

When I type mysitename.com/test.php it works perfectly with no issues. But when I type mysitename.com/public it downloads the php file instead of rendering it.

I just moved my site to another server and it supports php7 same as the old server.

Any idea guys? Thanks

13 Mar
4 months ago

lararocks left a reply on How Can I Select Certain Fields Using With()

Sorry it works; the space between the field list was causing an error.

lararocks left a reply on How Can I Select Certain Fields Using With()

@CRONIX - I tried to select the parent_id as well but it didn't work! It is one table anyway and here is the children function inside the Category model:

        return $this->hasMany('App\Category', 'parent_id');
}```

lararocks left a reply on How Can I Select Certain Fields Using With()

@JAYTEE - Thanks but it doesn't work for me! It throws an error.

$categories = Category::where('parent_id', 0)->with('children: id, name')->select('id', 'name')->get();

lararocks started a new conversation How Can I Select Certain Fields Using With()

How can I select certain fields using with().

My current query is:

$categories = Category::where('parent_id', 0)->with('children')->select()->get('id', 'name');

Currently children categories return all fields while I want children categories to only return id and name similar to parent/main categories.

Thanks

06 Nov
8 months ago

lararocks left a reply on File_put_contents() Issue

Code is perfect. I tried to post to a normal .php file and it saved all the images successfully. I think it is something wrong calling file_put_contents() from within a Laravel controller.

05 Nov
8 months ago

lararocks left a reply on File_put_contents() Issue

Hi Snapey, the post comes from an Android app. Some images get saved with no issues.

04 Nov
8 months ago

lararocks started a new conversation File_put_contents() Issue

Hello,

The following code works well on a core PHP site (no Framework, no Laravel) but on Laravel, the image gets saved but it is corrupted! Any idea why? Thanks

$fileName = date("YmdHis") . ".jpg";
$path = public_path().'/uploads/profiles/' . $fileName;
file_put_contents($path, $decodedImage);```
15 Jul
1 year ago

lararocks left a reply on Help With Query

Thanks so much it works :)

lararocks left a reply on Help With Query

Thanks @Tray2 it works but I still need to get the top 5 only.

lararocks started a new conversation Help With Query

Hello,

Sorry I'm not excellent in SQL and I need to write a plain sql query to get me the top 5 rated places by calculating the average rating for all services.

My tables

PLACE Table

  • id
  • country_id
  • is_active
  • name

RATING

  • id
  • place_id
  • service_id
  • rating

I tried the below but it throws an error:

$sql = "SELECT p.id as id, p.name as name, avg(r.rating) as rating FROM place p, rating r WHERE r.place_id = p.id AND p.country_id = 99 AND p.is_active = 1 GROUP BY r.place_id"; $results = DB::select($sql);

28 Mar
1 year ago

lararocks started a new conversation Get Top 5 Records Using Eloquent

I have the following table.

Review Table:

  • id
  • place_id
  • branch_id
  • review_text
  • review_date

I need to get the IDs of the top 5 reviewed places/branches.

Any idea how to do that with eloquent? Thanks

19 Mar
1 year ago

lararocks started a new conversation How To Send A Password Securely Through An API Endpoint

I'm building the API endpoints for a mobile app. The mobile will be accessing the create user endpoint to create a user from Laravel.

I'm just wondering how should the mobile securely send the password as an argument with the API call. Plain text is dangerous, so I need your suggestions on best practice please.

Thanks

15 Jan
1 year ago

lararocks left a reply on Access Specific Array From API Response

This worked for me. Thanks everyone.

return $data->{"2"}->{"10"}->{"mydata"};

lararocks left a reply on Access Specific Array From API Response

Thanks but it says:

Illegal string offset 'category_id'

lararocks started a new conversation Access Specific Array From API Response

Hello,

I'm using httpguzzle to get data from some API, and here is the result. I'm wondering how to access the "mydata" array directly. Any ideas?

array(1) {
  [2]=>
  array(6) {
    ["category_id"]=>
    string(1) "2"
    ["category_name"]=>
    string(7) "General"
    ["category_description"]=>
    string(101) "Description here"
    [2]=>
    array(10) {
      ["RE_TITLE1"]=>
      string(11) "First Title"
      ["RE_TITLE2"]=>
      string(12) "Second Title"
      ["brand_id"]=>
      string(1) "2"
      ["category_id"]=>
      string(1) "2"
      ["brand_name"]=>
      string(6) "Brand name"
      ["brand_description"]=>
      string(41) "Description here"
      ["mydata"]=>
      array(14) {
        [0]=>
        array(11) {
          ["data_id"]=>
          string(1) "13"
          ["data_name"]=>
          string(3) ""
        }
        [1]=>
        array(11) {
          ["data_id"]=>
          string(1) "14"
          ["data_name"]=>
          string(3) ""
        }
        [2]=>
        array(11) {
          ["data_id"]=>
          string(1) "15"
          ["data_name"]=>
          string(3) ""
        }
        [3]=>
        array(11) {
          ["data_id"]=>
          string(1) "16"
          ["data_name"]=>
          string(3) ""
        }
        [4]=>
        array(11) {
          ["data_id"]=>
          string(1) "17"
          ["data_name"]=>
          string(4) "0"
        }
        [5]=>
        array(11) {
          ["data_id"]=>
          string(3) "1130"
          ["data_name"]=>
          string(4) "0"
        }
        [6]=>
        array(11) {
          ["data_id"]=>
          string(3) "1131"
          ["data_name"]=>
        }
        [7]=>
        array(11) {
          ["data_id"]=>
          string(3) "1132"
          ["data_name"]=>
          string(4) "0"
        }
        [8]=>
        array(11) {
          ["data_id"]=>
          string(3) "1134"
          ["data_name"]=>
          string(3) ""
        }
        [9]=>
        array(11) {
          ["data_id"]=>
          string(3) "1135"
          ["data_name"]=>
          string(3) ""
        }
        [10]=>
        array(11) {
          ["data_id"]=>
          string(3) "1136"
          ["data_name"]=>
          string(4) "0"
        }
        [11]=>
        array(11) {
          ["data_id"]=>
          string(3) "1151"
          ["data_name"]=>
          string(2) ""
        }
        [12]=>
        array(11) {
          ["data_id"]=>
          string(3) "1214"
          ["data_name"]=>
          string(3) ""
        }
        [13]=>
        array(11) {
          ["data_id"]=>
          string(3) "1217"
          ["data_name"]=>
          string(4) "0"
        }
      }
    }
  }
}
13 Jan
1 year ago

lararocks started a new conversation My Custom Class Works On Localhost But Fails On Live Server

I have created a custom class

App\Custom\MyClass

I use it in my controller and it works perfectly, but this is the error I get on live site: Class 'App\Custom\MyClass' not found

Any idea? Thanks

31 May
2 years ago

lararocks started a new conversation Working With .svc Endpoints

Hello,

I received a .svc endpoint from my client but not sure which component/provider I can use to call such APIs. Can I use Guzzle for that? Kindly advise.

08 Feb
2 years ago
07 Feb
2 years ago

lararocks started a new conversation No Supported Encrypter Found. The Cipher And / Or Key Length Are Invalid.

My site works fine locally and on another shared hosting server. However, I'm trying to move the site to a new host but I got the following error when I moved the files and DB to the new host. Any idea please?

RuntimeException in EncryptionServiceProvider.php line 29: No supported encrypter found. The cipher and / or key length are invalid.

04 Feb
2 years ago

lararocks left a reply on Check If Text Is Encrypted Before Running Encrypt::decrypt($text)

Finally,

I was supposed to use DecryptException.

use Illuminate\Contracts\Encryption\DecryptException;

try {
    $decrypted = Crypt::decrypt($encryptedValue);
} catch (DecryptException $e) {
    //
}

Source: https://laravel.com/docs/5.2/encryption

lararocks left a reply on Check If Text Is Encrypted Before Running Encrypt::decrypt($text)

This is odd! Isn't there a simple function to check that?

Also, how come I get an error even when I use try catch??

01 Feb
2 years ago

lararocks left a reply on Check If Text Is Encrypted Before Running Encrypt::decrypt($text)

Laravel's build in algorithm Crypt::encrypt($text); Crypt::decrypt($encryptedText);

lararocks started a new conversation Check If Text Is Encrypted Before Running Encrypt::decrypt($text)

I'm using try catch but it throws an error if the text I'm trying to decrypt is not encrypted.

Thanks

07 Jan
2 years ago

lararocks started a new conversation Issue With HTTPS Redirect And Public Folder

Hi,

I'm using the middleware below to make sure all my routes are secured with https. The problem is that when I use this code, the public folder and all query strings get duplicated in the URL and I get an error. Example of what I get is:

https://www.mydomain.com/public/en/public/en

Middleware code is below: Thanks

<?php namespace App\Http\Middleware;

use Closure;
use Request;

class HttpsProtocol {

    public function handle($request, Closure $next){     
        
        if (!$request->secure() && env('APP_ENV') === 'prod') {
            if( ! $request->secure()){
                return redirect()->secure($request->getRequestUri());
            }
        }
        
        return $next($request); 
    }
}
?>
19 Dec
2 years ago

lararocks left a reply on Related Posts By Common Tags

Hi Snapey,

I tried your solution but it returned all rows!

I also had to change where(1,1) to whereRaw('1 = 1') after receiving an error.

18 Dec
2 years ago

lararocks left a reply on Apply Apache Authentication (.htpasswd) On Certain View Folder

To explain further, the authentication works on the entire Laravel site, while I want to only work on the admin folder/views.

This is my .htaccess

AuthUserFile /xampp/htdocs/my-laravel-site/.htpasswd
AuthType Basic
AuthName "Super Secret Site"
Require valid-user
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
</IfModule>

lararocks left a reply on Related Posts By Common Tags

Thanks guys.

SaeedPrez, that's the best practice I know, but it is not possible to re-code the app at this stage; it already has lots of data.

So, I wanted a solution for the current case where tags are stored in the same "posts" table and separated by comma.

lararocks started a new conversation Apply Apache Authentication (.htpasswd) On Certain View Folder

Hi,

I have an admin section with all views under "admin" folder.

I tried to apply Apache authentication on the admin folder but it didn't work.

I tried my code on a normal PHP script and it works, but not with Laravel!

Any idea how to achieve that?

Thanks

16 Dec
2 years ago

lararocks started a new conversation Related Posts By Common Tags

Hi,

I have a table called POSTS which has the following fields: ID, SLUG, NAME, CONTENT, and TAGS.

The TAG field stores data in this format (comma separated): mobile,android,htc

Now, in the single post view, I wish to also list all other posts with common tags.

Not sure how to do the where clause in my controller. Any idea?

Below is my controller code so far:

$posts = Post::where("ID", "=", $id)->where("slug", "=", $slug)->first();
$tags = $post->tags;
$related_posts = Post::where("ID", "!=", $id)->get(); // Need to do something here to compare tags
$data['post'] = $post;
$data['related_posts'] = $related_posts;
return view('posts.single', $data);
03 Dec
2 years ago

lararocks left a reply on Auth Session Expires Quickly

Thanks for helping everyone.

It was a missing break statement in my Exceptions/Handler.php file.

The code that was causing the issue:

public function render($request, Exception $e)
    {
        //return parent::render($request, $e);
        //return view('errors.custom');
        
        if ( ! config('app.debug') && ! $this->isHttpException($e)) {
            return response()->view('errors.custom');
        }
        
        
        if ($this->isHttpException($e)) {
            
            $statusCode = $e->getStatusCode();

            switch ($statusCode) {

                case '404':
                    return response()->view('errors.404');
                    break; // This was missing
            }
        }
        return parent::render($request, $e);
    }

Fixed it by adding the break statement.

Thanks all

02 Dec
2 years ago

lararocks started a new conversation Auth Session Expires Quickly

I'm using the default Laravel 5 auth controllers to authenticate users. After a user logs in, the session expires quickly in few seconds and redirects back to the auth/login page.

Any idea how to fix it?

I tries changing the expire value in config/auth.php but no luck.

02 Oct
2 years ago

lararocks started a new conversation RegEx Match

Hi, I have a text file with text and links. I need to match all the anchor tags where link text includes the word "product". It needs to be case insensitive.

Examples of links in the text file:

Product 1 Go to product x

Thanks

22 Sep
2 years ago

lararocks left a reply on Auth::check() Works In View But Not In Controller!

@bugsysha but why should I use a middleware if I just need a simple check to know if a user is logged in. Just need to use it in one of the methods.

lararocks left a reply on Auth::check() Works In View But Not In Controller!

@bestmomo,

This is what I'm doing. I'm using it in my method but it doesn't work!

21 Sep
2 years ago

lararocks left a reply on Auth::check() Works In View But Not In Controller!

OMG, seems that this is not straightforward in Laravel 5.3!!!

https://laravel.com/docs/5.3/upgrade#5.3-session-in-constructors

It is so odd to remove such thing!!

lararocks left a reply on Auth::check() Works In View But Not In Controller!

InaniELHoussain,

Same result!!

lararocks started a new conversation Auth::check() Works In View But Not In Controller!

Strange thing is that Auth::check() works fine in my view but always returns false in my controller. Using Laravel 5.3 My view:

@if (Auth::check())
<p>Welcome</p>            
@else        
<p><a href="{{ url('/signin') }}">Sign in</a></p>
@endif

My controller:

namespace App\Http\Controllers;
use App\Question;
use Request;
use Validator;
use Session;
use Auth;
use Input;
use App\Http\Controllers\Controller;


class QuestionController extends Controller{
    
    public function __construct(){
    }
    
    public function index(){
    }
    
    public function store(){
        if(Auth::check()){
            $input = Request::all();
            Question::create($input);
        }
    }
    
}
10 Sep
2 years ago

lararocks left a reply on Special Characters Issue In Route Parameters

Ori, how do I do that? How do I encode it before it reaches the controller?

lararocks started a new conversation Special Characters Issue In Route Parameters

Hi, I have a route that receives 2 parameters. Now everything works fine in my controller until any of the 2 parameters includes the # character.

In this case, the controller only takes the string before the # and ignores anything after.

Any fix for that please?

Thanks

07 Sep
2 years ago

lararocks started a new conversation API Token

Hi, I started preparing some API for the mobile app. Thing is that I want to make sure that API calls are only made by that mobile app and not by anything else.

I think there should be a token or secret key, etc... but I want to do this the right way in Laravel. Any resource or tutorial on that please?