mleontenko

mleontenko

Member Since 2 Years Ago

Experience Points
8,150
Total
Experience

1,850 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
58
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 2
8,150 XP
Oct
02
3 weeks ago
Activity icon

Replied to Optional Search Parameter Breaks Query

@michaloravec will definitely check it out, seems like a better practice. laracroft's answer was what I was exactly looking for at the time. Still getting the hang of laravel, the syntax for queries easily gets complex here...

Activity icon

Started a new Conversation Filter Collection With Relationship Value

I have a query result in a $users variable (I query User model). The queried model has a related model like this:

public function info()
    {
        return $this->hasOne('App\Info', 'user_id');
    }

Info object has a field called "json" that contains an array of integers.

I need to filter the results ($users variable) by value contained in related model's "json" column. How can I filter the collection with value in related objects?

Oct
01
3 weeks ago
Activity icon

Replied to Optional Search Parameter Breaks Query

@laracoft That looks good, but I get "Undefined variable: taksonomija" if I use it in function like that.

Activity icon

Replied to Optional Search Parameter Breaks Query

@laracoft I think it would work if I added the part below in parentheses, but I dont know how to do it...

and "razred"::text LIKE ? or "podrazred"::text LIKE ? or "nadred"::text LIKE ? or "red"::text LIKE ? or "porodica"::text LIKE ?
Activity icon

Replied to Optional Search Parameter Breaks Query

@laracoft

This is $query->toSql for my version:

"select * from "obrasciProcjeneVrste" where "znanstveno_ime"::text LIKE ? and "razred"::text LIKE ? or "podrazred"::text LIKE ? or "nadred"::text LIKE ? or "red"::text LIKE ? or "porodica"::text LIKE ? and "status" = ? and "id" not in (?, ?, ?)

And this is for yours:

"select * from "obrasciProcjeneVrste" where "znanstveno_ime"::text LIKE ? and "status" = ? and "id" not in (?, ?, ?) and "razred"::text LIKE ? or "podrazred"::text LIKE ? or "nadred"::text LIKE ? or "red"::text LIKE ? or "porodica"::text LIKE ? "
Activity icon

Replied to Optional Search Parameter Breaks Query

@laracoft it still ignores other filters. It looks like something in that block of code makes it override other query parameters.

Activity icon

Started a new Conversation Optional Search Parameter Breaks Query

I have the following query with some optional parameters that works fine:

$query = ObrazacProcjeneVrste::where('znanstveno_ime', 'LIKE', "%{$znanstvenoIme}%");
        if($skupina != 0) {
            $query = $query->whereHas('skupine', function($q) use($skupina) {
                $q->where('skupina_id', $skupina);
            });
        }
        if($datumDo != null) {
            $query = $query->where('created_at', '<=', $datumDo);
        }

        $query = $query->where('status', 'Prihvaćen')->whereNotIn('id', $id_eliminacija);
            
        $obrasci = $query->orderBy('datum_azuriranja', 'desc')->paginate(50);

If I add one more optional parameter that checks five columns for searched value, it does not take into account last filter ($query->where('status', 'Prihvaćen')...):

$query = ObrazacProcjeneVrste::where('znanstveno_ime', 'LIKE', "%{$znanstvenoIme}%");
        if($skupina != 0) {
            $query = $query->whereHas('skupine', function($q) use($skupina) {
                $q->where('skupina_id', $skupina);
            });
        }
        if($datumDo != null) {
            $query = $query->where('created_at', '<=', $datumDo);
        }

        if($taksonomija != null) {
            $query = $query->where('razred', 'LIKE', "%{$taksonomija}%")
                            ->orWhere('podrazred', 'LIKE', "%{$taksonomija}%")
                            ->orWhere('nadred', 'LIKE', "%{$taksonomija}%")
                            ->orWhere('red', 'LIKE', "%{$taksonomija}%")
                            ->orWhere('porodica', 'LIKE', "%{$taksonomija}%");
        }

        $query = $query->where('status', 'Prihvaćen')->whereNotIn('id', $id_eliminacija);
            
        $obrasci = $query->orderBy('datum_azuriranja', 'desc')->paginate(50);

What am I doing wrong here?

Sep
24
1 month ago
Activity icon

Replied to Raw SQL Query To Array

@sinnbeck That works, thanks!

Activity icon

Replied to Raw SQL Query To Array

@sinnbeck I'm getting the following error:

Symfony\Component\Debug\Exception\FatalThrowableError
Call to a member function pluck() on array
Activity icon

Started a new Conversation Raw SQL Query To Array

I'm using a raw SQL query that selects some ids from database. It looks like this:

$query = DB::select('SELECT pr.id_obrasca_prethodne 
        FROM public."prethodneNacionalneProcjene" AS pr 
        JOIN public."obrasciProcjeneVrste" AS ob ON pr.id_obrasca = ob.id WHERE ob.status LIKE \'Prihvaćen\'');

If I output the $query variable now, I get:

[{"id_obrasca_prethodne":8},{"id_obrasca_prethodne":28}]

I need to convert the result of query to PHP array so it contains only numbers (8, 28, ...). How can I do this?

Sep
15
1 month ago
Activity icon

Replied to Resource Middleware Exceptions

@sergiu17

If I do that, I get the following error when I try to open create form:

Illuminate\Database\QueryException
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "create" (SQL: select * from "obrasciProcjeneVrste" where "obrasciProcjeneVrste"."id" = create limit 1)

Auth middleware is also used on other routes. Could that be the problem?

Activity icon

Started a new Conversation Resource Middleware Exceptions

I have a controler named 'ObrasciController' expanded with a few aditional methods ('predaja' and 'search'). The routes look like this:

Route::get('obrasci/predaja/{id}', '[email protected]')->middleware('auth');
Route::get('obrasci/search', '[email protected]')->middleware('auth');
Route::resource('obrasci', 'ObrazacController')->middleware('auth')->middleware('checkAccess');

I want to except show and create method from 'checkAccess' middleware so that any user can create and view the resource. How can I do this? 'auth' middleware needs to be applied to all routes.

Aug
24
2 months ago
Activity icon

Started a new Conversation Query By Related Model Attributes

I have Post and Category models. One post can have many categories so I have many to many relationship stored in table named postsCategories.

postsCategories table has the following attributes: id, category_id, post_id

Post model:

public function categories()
    {        
        return $this->hasMany('App\PostCategory', 'post_id', 'id');
    }

Now, in my controller I have an array wih a list of category IDs:

$categories = array(2, 3) 

I want to fetch all posts that are in category 2 and 3 in the same controller. How can I create the query that filters the posts with $categories array?

Jul
30
2 months ago
Activity icon

Replied to Cloning Laravel Project (Ubuntu)

@bobbybouwmann my cloned application is not running at all because I cannot run

composer install

It returns the error described above.

If I create a new app, it works fine.

My first post is a bit messed up, and I cannot edit it because captcha solving is bugged :/

Activity icon

Replied to Cloning Laravel Project (Ubuntu)

@bobbybouwmann I already enabled it in php.ini.

But I don't thing it is the main problem here. It's just a warning.

See the part below the warnings, it tries to install all the dependencies and then returns:

"Your requirements could not be resolved to an installable set of packages."

And lists some problems.

Could it be that my new laptop has a newer version of php or laravel than the project?

Activity icon

Started a new Conversation Cloning Laravel Project (Ubuntu)

I have cloned a laravel project from my github on my new computer (Ubuntu 20.04). When I run composer install, I get the following message:

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /usr/lib/php/20190902/pdo_pgsql (/usr/lib/php/20190902/pdo_pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_pgsql.so (/usr/lib/php/20190902/pdo_pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: /usr/lib/php/20190902/pgsql (/usr/lib/php/20190902/pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pgsql.so (/usr/lib/php/20190902/pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  Module 'intl' already loaded in Unknown on line 0
PHP Warning:  Module 'mbstring' already loaded in Unknown on line 0
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for phpoffice/phpspreadsheet 1.14.0 -> satisfiable by phpoffice/phpspreadsheet[1.14.0].
    - phpoffice/phpspreadsheet 1.14.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
  Problem 2
    - phpoffice/phpspreadsheet 1.14.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
    - maatwebsite/excel 3.1.19 requires phpoffice/phpspreadsheet ^1.10 -> satisfiable by phpoffice/phpspreadsheet[1.14.0].
    - Installation request for maatwebsite/excel 3.1.19 -> satisfiable by maatwebsite/excel[3.1.19].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.4/cli/php.ini
    - /etc/php/7.4/cli/conf.d/10-opcache.ini
    - /etc/php/7.4/cli/conf.d/10-pdo.ini
    - /etc/php/7.4/cli/conf.d/15-xml.ini
    - /etc/php/7.4/cli/conf.d/20-calendar.ini
    - /etc/php/7.4/cli/conf.d/20-ctype.ini
    - /etc/php/7.4/cli/conf.d/20-dom.ini
    - /etc/php/7.4/cli/conf.d/20-exif.ini
    - /etc/php/7.4/cli/conf.d/20-ffi.ini
    - /etc/php/7.4/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.4/cli/conf.d/20-ftp.ini
    - /etc/php/7.4/cli/conf.d/20-gettext.ini
    - /etc/php/7.4/cli/conf.d/20-iconv.ini
    - /etc/php/7.4/cli/conf.d/20-intl.ini
    - /etc/php/7.4/cli/conf.d/20-json.ini
    - /etc/php/7.4/cli/conf.d/20-mbstring.ini
    - /etc/php/7.4/cli/conf.d/20-phar.ini
    - /etc/php/7.4/cli/conf.d/20-posix.ini
    - /etc/php/7.4/cli/conf.d/20-readline.ini
    - /etc/php/7.4/cli/conf.d/20-shmop.ini
    - /etc/php/7.4/cli/conf.d/20-simplexml.ini
    - /etc/php/7.4/cli/conf.d/20-sockets.ini
    - /etc/php/7.4/cli/conf.d/20-sysvmsg.ini
    - /etc/php/7.4/cli/conf.d/20-sysvsem.ini
    - /etc/php/7.4/cli/conf.d/20-sysvshm.ini
    - /etc/php/7.4/cli/conf.d/20-tokenizer.ini
    - /etc/php/7.4/cli/conf.d/20-xmlreader.ini
    - /etc/php/7.4/cli/conf.d/20-xmlwriter.ini
    - /etc/php/7.4/cli/conf.d/20-xsl.ini
    - /etc/php/7.4/cli/conf.d/20-zip.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

If I create a new laravel project on my machine and run it like this:

laravel new blog
cd blog
php artisan serve

What is the problem? Why can't I run the old app?

Then everything works fine.

Jul
21
3 months ago
Activity icon

Started a new Conversation Installing Laravel On Ubuntu

I'm trying to install laravel on Ubuntu 20.04 like this:

composer global require laravel/installer

It returns the following messages:

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /usr/lib/php/20190902/pdo_pgsql (/usr/lib/php/20190902/pdo_pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_pgsql.so (/usr/lib/php/20190902/pdo_pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: /usr/lib/php/20190902/pgsql (/usr/lib/php/20190902/pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pgsql.so (/usr/lib/php/20190902/pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  Module 'intl' already loaded in Unknown on line 0
PHP Warning:  Module 'mbstring' already loaded in Unknown on line 0
Changed current directory to /home/marin/.config/composer
Using version ^3.2 for laravel/installer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
11 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Now, when I try to run:

laravel new blog

It returns the following message:

laravel: command not found

What is wrong here?

Jun
30
3 months ago
Activity icon

Replied to Filter By Attribute From Pivot Table

@frankielee I'm using this operators() method in view while rendering, so I cannot use controller here.

I have three possible roles, so I'm planning to add three separate methods for fetching all the users with the role. The one above is just for example.

Activity icon

Started a new Conversation Filter By Attribute From Pivot Table

I have the following method in my model that retrieves all the related users and their roles:

public function operators()
{
        return $this->belongsToMany('App\User', 'obrasciOperateriUloge', 'id_obrasca', 'id_operatera')->withPivot('role');        
}

The results look like this:

[
   {
      "id":8,
      "name":"jjozic",
      "firstname":"Jozo",
      "lastname":"Jozi\u0107",
      "email":"[email protected]",
      "email_verified_at":null,
      "admin":false,
      "active":true,
      "phone":"555",
      "created_at":"2020-03-09 11:26:16",
      "updated_at":"2020-03-09 11:26:16",
      "edited_by":null,
      "edited_at":null,
      "pivot":{
         "id_obrasca":43,
         "id_operatera":8,
         "role":"Author"
      }
   },
   ...
]

I want to add an aditional filter in operators() method that returns only the users with role "Author". How can I do this?

Jun
15
4 months ago
Activity icon

Started a new Conversation Set Attribute Based On Id

I have an object model that has an attribute named "code" that is generated based on object id. The problem is I cannot access object id in my controller before it is stored because it is auto increment. Is there a simple way to add "code" attribute when storing object?

The "code" attribute would contain id with leading zeros like this:

str_pad($object_id, 6, '0', STR_PAD_LEFT);
May
24
5 months ago
Activity icon

Replied to Display Time With Timezone

@snapey thanks, was not aware that I can set timezone in config/app.php. That should work for me in this case.

Activity icon

Started a new Conversation Display Time With Timezone

I have a Post model that contains creation date in timestamp without timezone:

$table->dateTime('creation_date');

Example: 2020-05-22 09:54:34

It seems to store dateTime in GMT time zone andshows it like that in my view:

{{ date('d.m.Y. H:i', strtotime($post->creation_date)) }}

I want to convert it to local timezone in view. How can I do that?

May
20
5 months ago
Activity icon

Replied to Query With Attributes From Related Model

@michaloravec Thanks, that will work!

I used Post - Category analogy only for example, my app has entirely different classes that would be harder to explain. It's true this logic would be wrong in Posts and Categories case...

Activity icon

Started a new Conversation Query With Attributes From Related Model

I have a Post model that can have multiple categories:

The relationship looks like this:

public function categories()
    {
        return $this->hasMany('App\PostsCategories', 'post_id', 'id');
    }

PostsCategories table contains IDs of posts and their categories.

I'm trying to query posts by multiple criteria (post name, category, etc.) like this:

public function search(Request $request)
{   
    $post_name= $request->post_name;
    $category_id= $request->category_id; // value is integer 1- 20

    $posts= Post::query()
            ->where('post_name', 'LIKE', "%{$post_name}%")
            // and where category equals $category_id
            ->paginate(50);
}

I'm having trouble with figuring out how to add category to my query. How can I include attributes form related models in my query?

Apr
28
5 months ago
Activity icon

Started a new Conversation Retain Value Of Radio Button, But Set Default Value

I'm using old() to retain radio button selection after form validation error in Laravel, but I also want to make option "Unknown" selected by default.

The form element looks like this:

<label for="description">Product Available</label><br/>
<label class="radio-inline"><input type="radio" name="available" id="available" value="yes" {{ (old('available') == 'yes') ? 'checked' : ''}}>Yes</label>
<label class="radio-inline"><input type="radio" name="available" id="available" value="no" {{ (old('available') == 'no') ? 'checked' : ''}}> No</label>
<label class="radio-inline"><input type="radio" name="available" id="available" value="unknown" {{ (old('available') == 'unknown') ? 'checked' : ''}}> Unknown</label>

This works fine, but I need the "Unknown" option to be set by default when opening form without overriding "old()" data.

How can I do this?