kima

kima

Member Since 1 Year Ago

Experience Points
2,730
Total
Experience

2,270 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
4
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
2,730 XP
24 Jul
1 month ago

kima left a reply on Multiple Find Query In Single Database Connection

find function is able to receive an array in the $id argument:

$departments = Department::find([1, 2, 3, 4, 5, 6, 7])
23 Jul
1 month ago

kima left a reply on Cannot Create A Simple Array

The chunk works with an anonymous function, thus the sitemap is not in your scope. you should declare $sitemap before the chunk function, and add it with a use to the anonymous function:

        $sitemap = [];

        Listing::where('Inactive', '=', 0)
            ->where('Status', '=', 'Active')
            ->chunk(200, function($listings) use ($sitemap) {
            foreach($listings as $listing) {
                $sitemap[] = array (
                    $cleanURL = "https://listingnaples.com/listing/" . $listing->MLSNumber . "/" . $listing->CleanAddressURL,
                    "loc" => $cleanURL,
                    "changefreq" => "daily",
                    "priority" => "0.90"
                );
            }
        });

kima left a reply on Filter Model Entry Laravel Collection

I didn't understand your logic, but at notice that the where function is immutable, and you need to set the $allUsers as the result:

$allUsers = $allUsers->where($key, 1)

kima left a reply on One To One Relationship From The Same Table

The save functions in add_spouse should get the member model and not the spouse id

public function add_spouse($spouse_id)
    {
        $spouse = Member::find($spouse_id);
        $this->spouse()->save($spouse);
        $spouse->spouse()->save($this);
    }
21 Jul
2 months ago

kima left a reply on How To See Curl Output?

Please show your ApiRequest::curlRequest method

11 Jul
2 months ago

kima left a reply on Find And Replace In Laravel Collection

@zaheer Please change the $rslt = DB::table('journal') to $rslt = YoutModelName::query()

When you are querying with DB::table, the records are returned as stdClass, with no Eloquent features.

27 Jun
2 months ago

kima left a reply on How To Convert Following Sql Query To Laravel Query Buillder?

DB::raw has no $bindings parameter. please try this:

 $query  = DB::table('branch')
            ->select(['id', 'name'])
            ->selectRaw("( 3959 * acos ( cos ( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( latitude ) ) ) ) as distance", [$latitude, $longitude, $latitude])
            ->having("distance", "<", $request->distance)
            ->orderBy('distance', 'asc')
            ->offset(0)
            ->limit(20);

        $data = $query->get();

kima left a reply on How To Convert Following Sql Query To Laravel Query Buillder?

@ssquare accourding to your updated code, your having should be removed from the ->select() clause, to a ->having() clause:

        $query  = DB::table('branch')
            ->select(
                'id',
                'name',
                \DB::raw('( 3959 * acos ( cos ( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( latitude ) ) ) ) as distance')
            )
            ->having("distance", "<", $request->distance)
            ->orderBy('distance', 'asc')
            ->offset(0)
            ->limit(20);

        $data = $query->get();
26 Jun
2 months ago

kima left a reply on Call To A Member Function Save() On Array

It should work. please send here the current code and a JSON of $data

kima left a reply on Call To A Member Function Save() On Array

$document var is actually not a model, but a models array. you should save the model in $document var, save it, and then add it to a $documents array

        // Before the foreach
        $documents = [];
        
        // Inside foreach
        $document = new Document(array(
            'user_id'=>$request->get('user_id'),
            'doc_type' => $files,
            'doc_path' => $picName,
        ));
        $document->save();
        $documents[] = $document;

another option is to use the tap() helper, like:

        $document[] = tap(new Document(array(
            'user_id'=>$request->get('user_id'),
            'doc_type' => $files,
            'doc_path' => $picName,
        )), function ($document) { $document->save(); });
18 Jun
3 months ago

kima left a reply on Call To A Member Function ToArray() On Null

@SWIMMER - It depends on your implementation. how do you call it?

Are there situations when you have no Menu model for this $url? If no, do you check that the getAll() result is an array before you iterate it? if you iterate it at all

17 Jun
3 months ago

kima left a reply on Unable To Do Php Artisan Migrate

I'm not familiar with the mysqlnd extension, but I check the php.net (https://www.php.net/manual/en/mysqlnd.install.php) page and noticed this:

The MySQL database extensions must be configured to use the MySQL Client Library. In order to use the MySQL Native Driver, PHP needs to be built specifying that the MySQL database extensions are compiled with MySQL Native Driver support. This is done through configuration options prior to building the PHP source code.

As I can see, you have no other DB extention, mysqli for example

kima left a reply on Unable To Do Php Artisan Migrate

I noticed some issues in StackOF, all of them pointing to the mysqlnd extension. Please check your php-mysqlnd extension is updated to your php version, and loaded properly by Apache. Restart Apache if needed.

kima left a reply on Unable To Do Php Artisan Migrate

Are you using a debugger?

kima left a reply on Unable To Do Php Artisan Migrate

Please set the DB_CONNECTION value in your env file to lower case, as there is no 'MySql' key in your connections array

kima left a reply on Call To A Member Function ToArray() On Null

You need to use ->first(), to actually fetch the record from the database, but with no ->toArray() function. Please try this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class content extends Model
{
    static public function getAll($url){
        if($menu = Menu::where('url', '=', $url)->first()) {
            $content = Content::where('menu_id', '=',$menu->id)->get()->toArray();

            return $content;
        }
        
        return [];
    }
}

kima left a reply on Call To A Member Function ToArray() On Null

I don't understand the logic here, but it seems like you try to do a Menu existing validation, but the validation breaks when there is no Menu and the first() function returns null. so please try to remove the first toArray()

kima left a reply on Multiple Model Updating

@CHRISTOPHHARMS - @keizah Both databases should work with no backticks at all:

$neighbours = Category::where('left', '>', $category->right);

$neighbours->update([
    'left' => DB::raw('left+2'),
    'right' => DB::raw('right+2'),
]);

@ChristophHarms This is not a Collection, the $neighbours variable is still a QueryBuilder as it didn't use the get() method.

11 Jun
3 months ago

kima left a reply on Query Builder To Collection Of Models.

why not using

ModelClass::query()->select

?

if you want to use the hydrate function you can use it like

ModelClass::hydrate($results->toArray())
10 Jun
3 months ago

kima left a reply on Where Clause Depending On Column Value

the when clause is for PHP boolean and not being interpreted in SQL. Please try to set the DB::raw inside the the Join clause

->join("person_fields", function(\Illuminate\Database\Query\JoinClause $join){
                        $join->on('person_fields.name','Name')
                             ->where('person_fields.person_type','Family Member')
                             ->whereRaw('person_vatas.member_id IS NOT NULL');
                        });
15 May
4 months ago

kima left a reply on Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message Why?

Did you make sure the routes files are not cached? Please run 'php artisan route:clear' and try again

05 May
4 months ago

kima left a reply on Merging Two Queries With Eloquent

You have 2 options.

You can set a variable that will reference to the QueryBuilder, do your logic and then apply more clauses on the variable and get the result

$builder = Ad::query()
            ->whereHas('book', function (\Illuminate\Database\Eloquent\Builder $query) use ($book_id) {
                $query->where('book_id', $book_id);
            });
        
        if (true) {
            $builder->whereHas('authors', function (\Illuminate\Database\Eloquent\Builder $query) use ($checkbox) {
                $query->whereIn('ad_service.author_id', $checkbox);
            });
        }
        
        $result = $builder->get();

Another option is to use the when function

Ad::query()
            ->whereHas('book', function (\Illuminate\Database\Eloquent\Builder $query) use ($book_id) {
                $query->where('book_id', $book_id);
            })->when("some condition", function (\Illuminate\Database\Eloquent\Builder $query) use ($checkbox) {
                $query->whereHas('authors', function (\Illuminate\Database\Eloquent\Builder $query) use ($checkbox) {
                    $query->whereIn('ad_service.author_id', $checkbox);
                });
            })->get();
12 Feb
7 months ago

kima left a reply on Automatic Injection On Anonymous Functions?

how does $factory getting instantiated?

It uses Laravel dependency injection. It is important to read this article to understand: https://laravel.com/docs/5.7/container

Faker\Generator and Eloquent\Factory have to be constructed with required parameters, and Laravel doing this for you in a singleton pattern. When you just use new Faker() you are not set these parameters!

Laravel registers (instantiated) the Faker\Generator and Eloquent\Factory in DatabaseServiceProvider::registerEloquentFactory() function. Whenever the application needs a Faker\Generator, it would inject the instance that was set.

How does the closure getting called?

As you see, the $factory->define() function saving the $attributes (actually an anonymous function) in the singleton under 'definitions' member (and already has 'faker' member)

When you using the factory() helper, it uses the Illuminate/Database/Eloquent\Factory::of() function. in the end, it is calling Illuminate/Database/Eloquent/FactoryBuilder::getRawAttributes(). this function calls your anonymous function with the 'faker' member, which is the Faker\Generator singleton

kima left a reply on Automatic Injection On Anonymous Functions?

It is not an Automatic Injection

The $factory is an Eloquent\Factory class, that has a 'faker' member that was set in the constructor. When your app is trying to resolve the defined class, it injects the 'faker' member to the anonymous function.

The default faker is set in DatabaseServiceProvider

If you just want a faker instance, you can use app(\Faker\Generator::class);

24 Dec
8 months ago

kima left a reply on Database Tables Created Without Migration

Receive the Model table name by $table member with fallback by the class name:

with(new static)->getTable() When static is a Model

17 Dec
9 months ago

kima left a reply on Filesystem Disk Per User

@MOENCHFRACHT - I don't see it part of a service provider and not using guards to detect the user, as I assume that the system admin should reach this storage although he is not logged in to the specific user, or using multiple user's storage paths in one session

in this case, I would just add it in the User class or creating a factory for this.

public function getStorageInstance()
    {
        $dir = storage_path('app/public/'.$this->name.'/');
        // Make sure the storage path exists and writeable
        if (!is_writable($dir)) {
            mkdir($dir, 0777, true);
        }

        return Storage::createLocalDriver(["root" => $dir]);
    }

kima left a reply on Filesystem Disk Per User

I prefer to not use variables in the config files as I cache them in Production environments.

Try using Storage::createLocalDriver(["root" => storage_path('app/public/'.\App\Auth::user()->name.'/')]);

You might create a function that returns you a storage instance for a user. the function can handle the directory creation and directory permissions also.