winner1

winner1

Member Since 9 Months Ago

Experience Points 2,950
Experience Level 1

2,050 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 23
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

18 Apr
1 month ago

winner1 started a new conversation Generating Guest Tokens

I'm using passport on my project

I want to make some specific routes accessible for all of my API users without using username and password to take an access token

the reason is that some routes like reading a table records should be usable for all of my android application users to load posts and ... without registering(tell me if this is not the best way to make that possible!)

lets suppose user can use this endpoint to obtain a guest access token:

mysite.com/api/oauth/authGuest

and result should be something like:

{"token_type":"Bearer","expires_in":863999,
"access_token":"token",
"refresh_token":"refToken"}

after that, user can access guest-allowed routes

do you have any idea that which method should I use?

I also checked this question but I'm not so familiar to jwt:

https://stackoverflow.com/questions/42487333/laravel-passport-guest-token

thanks in advance

winner1 left a reply on Creating A Password Grant Client Without Artisan Command!(passport Library)

i finally fixed this by generating a custom route that adds the client id and secret to the request and sends it to the original route (i also renamed the original route to something else and used that URL for my custom route)

Route::post('/oauth/token',function(Request $request){

    $request->request->add([
        'grant_type'    => 'password',
        'client_id'     => '[my id]',
        'client_secret' => '[my secret]',
        'scope' => '*'
    ]);


    // forward the request to the oauth token request endpoint
    $tokenRequest = Request::create('/oauth/[original-changed-url]','post');
    return Route::dispatch($tokenRequest);
});

winner1 left a reply on Creating A Password Grant Client Without Artisan Command!(passport Library)

i finally fixed this by generating a custom route that adds the client id and secret to the request and sends it to the original route (i also renamed the original route to something else and used that URL for my custom route)

Route::post('/oauth/token',function(Request $request){

    $request->request->add([
        'grant_type'    => 'password',
        'client_id'     => '[my id]',
        'client_secret' => '[my secret]',
        'scope' => '*'
    ]);


    // forward the request to the oauth token request endpoint
    $tokenRequest = Request::create('/oauth/[original-changed-url]','post');
    return Route::dispatch($tokenRequest);

});

winner1 left a reply on Creating A Password Grant Client Without Artisan Command!(passport Library)

i finally fixed this by generating a custom route that adds the client id and secret to the request and sends it to the original route

30 Jan
3 months ago

winner1 started a new conversation Creating A Password Grant Client Without Artisan Command!(passport Library)

I'm testing password grant type by Passport library first i made a client by this command and got a client id and secret:

php artisan passport:client --password

and i sent the following fields to /oauth/token endpoint: grant_type,client_id,client secret,username,password and got something like this:

{"token_type":"Bearer","expires_in":863999,
"access_token":"token",
"refresh_token":"refToken"}

so far so good

but i don't know how to make this password grant client for my users because obviously, they can't access my terminal!

should i add these fields to users request as static fields(in my code) or even is really using client secret and id necessary for password grant type?

Thanks in advance

31 Dec
4 months ago

winner1 left a reply on Laravel 5.4 - PostTooLargeException In ValidatePostSize.php Line 22:

the question is pretty old but it may help someone I fixed this error by editing my php.ini file:


upload_max_filesize = 2048M```

according to this topic:```
https://stackoverflow.com/questions/28529518/small-file-get-uploaded-but-not-large-file-in-laravel
06 Dec
5 months ago

winner1 started a new conversation Upload Files To An Alternative Server

I'm trying to get the posted file and send it to an alternative server that saves the files and handles file request like a directory listing

let's suppose my that alternative server doesn't use Laravel(Plain PHP), I don't want to use FTP because I found out its a little(or more!) slow

should I use curl or is there any special way in Laravel? Thanks in advance

26 Nov
5 months ago

winner1 left a reply on Removing Full Path From Ftp Storage Directory Listing Result

@REALRANDYALLEN - That Worked Perfectly!!

  • I also changed getDirectories method using your code to:
 public function getDirectories($dir = null)
    {
        $dirs= collect($this->driver->directories($dir));
        return $dirs->map(function ($d) {
            $name = preg_split('#/#', $d);
            return array_pop($name);
        });
    }

Thanks a lot

25 Nov
5 months ago

winner1 left a reply on Removing Full Path From Ftp Storage Directory Listing Result

@REALRANDYALLEN - thanks for the reply my ftp class doesn't extend other classes it's a simple class that returns the proper driver and settings for each user:

<?php
namespace App\Http\Helpers;


use Illuminate\Support\Facades\Storage;

class FTP 
{
   //..
    public static function getFtpDriver($projectId){//it chooses the server depended on user project id but I just simplified it for now


            return Storage::disk('mainServer');
            
    }
//..
}

which class should i use as a superclass to use that method?

winner1 started a new conversation Removing Full Path From Ftp Storage Directory Listing Result

I'm trying to provide an endpoint that shows directories and folders in a JSON response(by Laravel ftp filesystem), here is my function code: `` public function showDir($projectId,Request $req){ $dir=$req->get('path');//folder1 $ftpStorage=FTP::getFtpDriver($projectId);//FTP is my custom class to access the ftp storage $dirs=$ftpStorage->directories($dir); $files=$ftpStorage->files($dir);

    return response()->json(['directories'=>$dirs,'files'=>$files]);
}``

and the example result:

{
    "directories": [
        "folder2/folder1infolder2",
        "folder2/folder2infolder2"
    ],
    "files": [
        "folder2/file1infolder2.txt"
    ]
}```
as you see it works and shows folders and files inside folder1, but it shows the full path of folders and files, what I supposed to do is:

{ "directories": [ "folder1infolder2", "folder2infolder2" ], "files": [ "file1infolder2.txt" ] }``` is there any special way or I should use methods like PHP str_replace or..? Thanks in advance

11 Oct
7 months ago

winner1 left a reply on Chuck Vs Pagination! Memory Usage

@thoasty thanks, but the thing i wanted to know is that does pagination work like chunk in the background(chunks result and retrieves data per page not all of the data at once) when you said about paginate i found this question and sounds they are same in this case https://laravel.io/forum/08-13-2016-how-pagination-works

winner1 started a new conversation Chuck Vs Pagination!memory Usage

as laravel doc says: If you need to process a lot (thousands) of Eloquent records, using the chunk command will allow you to do without eating all of your RAM:

so what about pagination?

for example is:

same as
{
    foreach ($users as $user)
    {
        //
    }
});

in memory usage?

07 Sep
8 months ago

winner1 left a reply on Returning Normal Text Of Urls Using Response()->json()

@Cronix oh

now I see its fine in the browser(i checked it in postman)

thanks

winner1 started a new conversation Returning Normal Text Of Urls Using Response()->json()

I'm trying to return an URL in my response by using response()->json() method , something like this:

but the result is:
```{"url":"http:\/\/example.com"}
response line:
``` return response()->json(['url'=>'http://example.com'] , 200);

i don't want to use normal PHP echo function
any idea?
thanks in advance
22 Aug
8 months ago

winner1 left a reply on Reading Query Where Clause Conditions As JSON And Converting It To SQL Query

Finally got the solution according to Jarek Tkaczyk answer in this thread: link:https://stackoverflow.com/questions/19325312/how-to-create-multiple-where-clause-query-using-laravel-eloquent[How to create multiple where clause query using Laravel Eloquent?] we can run our queries using laravel in this template:

where([ ['column_1', '=', 'value_1'], ['column_2', '<>', 'value_2'], [COLUMN, OPERATOR, VALUE], ... ]) here is my new code: if (isset($query)) {

        $fullQuery = [];
        /*
         https://stackoverflow.com/questions/19325312/how-to-create-multiple-where-clause-query-using-laravel-eloquent
         template:
         where([
         [COLUMN, OPERATOR, VALUE],
         ['column_1', '=', 'value_1'],
         ['column_2', '<>', 'value_2'],
        */

        try {

// $query = '{"working_years":{">":2,"<":5,"<>":3},"car_name":"bmw","car_company":"abc"}'; $i = 0; foreach (json_decode($query,true) as $key => $value) {

                if (is_array($value)) {//has custom where condition

                    $count=count($value);
                    $j = 0;
                    foreach ($value as $whereKey => $whereValue) {
                        $fullQuery[$i+$j][0]=$key;
                        $fullQuery[$i+$j][1]=$whereKey;
                        $fullQuery[$i+$j][2]=$whereValue;
                        $j++;
                    }
                    if ($count>0)
                    $i+=($count-1);
                } else {
                    $fullQuery[$i][0]=$key;
                    $fullQuery[$i][1]='=';
                    $fullQuery[$i][2]=$value;
                  }


                $i++;

            }
        } catch (\Exception $exception) {
            return $this->customError($exception->getMessage(), 30, 500);
        }
        return $table->where($fullQuery)->first();

winner1 left a reply on Reading Query Where Clause Conditions As JSON And Converting It To SQL Query

@aurawindsurfing yes, not a model for a table, its a model for all of DB tables(we connect tables to that model by table name dynamically)

21 Aug
8 months ago

winner1 left a reply on Reading Query Where Clause Conditions As JSON And Converting It To SQL Query

thanks, @aurawindsurfing but i don't have a static model, users choose their table and i connect that table name to a model thanks to a trait but the problem is running this type of complex query on a database I prefer eloquent or any laravel stuff than pure PHP code but i don't know how, or even that's possible or not because queries are not simple like "$query->where('votes', '>', 100);" a user can add many conditions for each table columns and

winner1 started a new conversation I'm Using PHP Laravel Framework What I Want Is Accessing Query WhereClause Parameters And Converting It To A String Query To Read Records From Database Ex: Converting This:

what I want is accessing query whereClause parameters and converting it to a string query to read records from database by eloquent where or whereRaw method ex: converting this:

{"working_years":{"$greaterThan":2,"$lowerThan":6},"car_name":"someName","car_company":"companyName"} to: working_years > 2 AND working_years < 5 AND car_name=someName AND car_company = companyName my current code: (it only reads and saves uery parametrs and whereclause operators in arrays) // $query=$request->where; //for now we access it from a string: $query = '{"working_years":{"$greaterThan":2,"$lowerThan":6},"car_name":"someName","car_company":"companyName"}';

    if (isset($query)) {


        $i = 0;
        $whereFieldsAndVals = array([]);// ex:-> [10][name,abc]

        try {

            $operator = array([]);// ex:-> [10][=,>]
            foreach (json_decode($query) as $key => $value) {


                if (is_object($value)) {//has custom conditions

                    $j = 0;
                    foreach ($value as $k => $v) {

                        $operator[$i][$j] = $k;
                        $whereFieldsAndVals[$i][1] = $v;
                        $j++;
                    }

                } else {
                    $whereFieldsAndVals[$i][1] = $value;
                }
                $whereFieldsAndVals[$i][0] = $key;



                $i++;

            }
        } catch (\Exception $exception) {
            return $this->customError($exception->getMessage(), 30, 500);
        }

                }

                return $operator;
                //this will return:
                //[[">","<"]]
                return $whereFieldsAndVals;
                //this will return:
                //[{"1":6,"0":"working_years"},{"1":"someName","0":"car_name"},{"1":"companyName","0":"car_company"}]

}
11 Aug
9 months ago

winner1 started a new conversation Unable To Use POST Method In Laravel Web Routes

Hey I'm trying to add a post route to my web routes but when i try to check the route, the result is this message:

"The page has expired due to inactivity.

Please refresh and try again."

(status code is 419) my route: Route::post('/posttest', '[email protected]');

the referenced method in controller: public function test(Request $request){ return "text"; }

this route works in api routes but not on web routes(what i need) thanks in advance