Sergiu17

Sergiu17

Chisinau

Member Since 1 Year Ago

Experience Points 206,550
Experience
Level
Lessons Completed 1273
Lessons
Completed
Best Reply Awards 116
Best Answer
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.

16 Nov
18 hours ago

Sergiu17 left a reply on Share Methods/functions Between Multiple Console Commands?

@ERIKGYEPES - a Service - yes, a Controller - no. Controller is just for request/response.

You can create a Service an inject it in your commands

Sergiu17 left a reply on Share Methods/functions Between Multiple Console Commands?

Hi, a Trait? Or may be Parent Class?

14 Nov
2 days ago

Sergiu17 left a reply on Adding An Increasing Number After A Variable In Blade

@php $i = 1 @endphp

@foreach ($products as $product)

    @php $i++ @endphp
@endforeach

Sergiu17 left a reply on Multiple File Upload

@LAWKUNCHI - That's true, you need to implode this array into a string, or whatever you chose.

'docs' = implode(', ' $paths);

You may store as JSON, or create a separate table for files

Sergiu17 left a reply on How Can I Run Composer Commands On Server ?

Simplest way is to download composer.phar file and put it in root of your laravel app, and to run in

php composer.phar list

Sergiu17 left a reply on Multiple File Upload

So what's the problem? Can't save an array ( paths ) into docs column?

13 Nov
3 days ago

Sergiu17 left a reply on Display Date On Pages Site Wide (via Master Layout Through Include)

Why you don't use JavaScript for this?

12 Nov
4 days ago

Sergiu17 left a reply on Jeffery Ways "Favorite This"

Let's take step by step. Laravel 5+ ( I guess ) there's no more ->before(), you should use middleware instead

// example
Route::('/rates', function() {})->middleware('auth');

Now about undefined favorites variable, take baby steps

// Route
Route::get('users/{id}/favorites', function ($userId)
{
    $listings = User::findOrFail($userId)->favorites;

    return view('rates', compact('listings')); // you send here only one variable, which is not favorites. You should rename this variable to 'favorites' since you grab user's favorites
});
// should be like so
Route::get('users/{id}/favorites', function ($userId)
{
    $favorites = User::findOrFail($userId)->favorites;

    return view('rates', compact('favorites '));
});

Now you can access favorites variable

Sergiu17 left a reply on Bulk Insert Using DB::

Sure

DB::table('users')->insert([
    [
        'name' => 'John',
        'email' => '[email protected]'
    ],
    [
        'name' => 'Mary',
        'email' => '[email protected]'
    ]
]);

Sergiu17 left a reply on File .env

After editing .env file, make sure you run php artisan config:clear

09 Nov
1 week ago

Sergiu17 left a reply on Path Resolution In PHPStorm

Hi! Usually for css, images, and js I use

asset()

Sergiu17 left a reply on Looking For The PHPStorm Selection Keybinding

Looks like this is what you need, in my case is set to ALT+E, but I've modified it. It's called Extend Selection

Sergiu17 left a reply on How Do I Test Login Throttling?

@D9705996 - Yes, you are right, more appropriate would be to assert status code, or better as you did with assert contain. That's why I said my 5 pennies :D Thanks!

Sergiu17 left a reply on How Do I Test Login Throttling?

My 5 pennies

Route::get('/testing-throttle', function () {
    return response('Success', 200);
})->middleware('throttle:1,1');
/**
* @test
*/
public function testing_throttle()
{
    $response = $this->get('/testing-throttle');
    $response->assertStatus(200);

    $response = $this->get('/testing-throttle');
    $response->assertHeader('X-RATELIMIT-REMAINING', 0);
}

Laravel responds with X-RATELIMIT-REMAINING header when limit is reached

Sergiu17 left a reply on Fetch Most Recent Message Sent To Me Per User

@JARJARSLOTH - That's awesome, look how you can do this

public function messages()
{
    return $this->hasMany(Message::class)->orderBy('created_at', 'desc');
}
$messages = auth()->user()->messages;

foreach($messages as $message) {
    var_dump($message->user_id);
    var_dump($message->message); // sounds weird $message->message, but you can change variable names;
}

Done. And if you want something else, you can do

$messages = auth()->user()->message()->get()->toArray();

Sergiu17 left a reply on Eloquent Method Does Not Exist

@D9705996 - Ohh, sorry, thank you ;) edited*

Sergiu17 left a reply on Fetch Most Recent Message Sent To Me Per User

Read more about GROUP BY in MySQL, it usually returns one row if there's a where id = $id

What is your relationship between App\User and App\Message ?

Sergiu17 left a reply on Datatables - No Error Message In Console - But No Rows Displayed

Can you do a console.log(data) to see what do you get?! I think you may need to do

return [data.stories]; // data.stories

Sergiu17 left a reply on Eloquent Method Does Not Exist

@BOLDSTAR - Now, read the first post I guess :D

Sergiu17 left a reply on Datatables - No Error Message In Console - But No Rows Displayed

@MKOJOA - OK, now check if JS sends the request, people often forget to include the script in html

<script src="app.js"></script>
<script src="table.js"></script>

Sergiu17 left a reply on Datatables - No Error Message In Console - But No Rows Displayed

Does this url return something http://localhost:8000/stories ?

If yes, make sure JS sends request to this end point

Sergiu17 left a reply on Eloquent Method Does Not Exist

@BOLDSTAR - ``` $workflow = Workflow::where('id', $validated['id'])->firtOrFail();

Try to use `firstOrFail` instead of `get()`

Sergiu17 left a reply on Eloquent Method Does Not Exist

$workflow = Workflow::where('id', $validated['id'])->get(); // returns a collection

$workflow->statuses() // can't call statuses() on collection

Sergiu17 left a reply on Model Self Instantiating Via Factory-like Static Methods

$product = new Product();
$product->price = '1000';
$product->save();

$product->order()->create();

I think this should work, if you have relationships and it looks much better

08 Nov
1 week ago

Sergiu17 left a reply on Eloquent Daterange But Diferent!

@AMARO - Got it, the same code, but with few operations before

$startDate = '31-12-2018';
$endDate = date('d-m-Y', strtotime($startDate . ' - 15 days'));

Notice::whereBetween('numberdaystoalert', [$startDate, $endDate])->get();

Like so!

Sergiu17 left a reply on Adding A / To A String

<form action="/view/dmca" method="..

Keep it simple

Sergiu17 left a reply on Eloquent Daterange But Diferent!

Notice::whereBetween('numberdaystoalert', [$startDate, $endDate])->get();

If I understood you

Sergiu17 left a reply on Core PHP Vs Laravel

https://github.com/laravel/framework/tree/5.7/src/Illuminate - all this things you don't have to create from scratch :)

07 Nov
1 week ago

Sergiu17 left a reply on Samsung Phone

@jlrdw I don't want to tell you about my BlackBerry Z10 :D

Sergiu17 left a reply on How To Count Table Column Type In Laravel 5.6?

@SUNPOWER - ``` Model::where('type', 'car')->count();

Like so?!

Sergiu17 left a reply on Please Bring Back The Older Laracasts Design

I never knew 'How to clear notifications', now I saw @mo7sin 's print screen and there's clear all button, but because I had ~200 notifications, I couldn't see that button, and the section is unscrollable, is this only on my side?! ( tested on FireFox and Chrome )

This is how I've deleted them: Inspect Element, hide all notifications, and the buttons appears :) And now I have 0 notifications, which is nice

Sergiu17 left a reply on How To Count Table Column Type In Laravel 5.6?

Model::groupBy('type')->select('type', \DB::raw('count(*) as Total'))->get();

Sergiu17 left a reply on You Don't Have Permission To Access /images/ On This Server

Make sure you have permissions, I think that there's no images folder, try to create images folder, then try again, otherwise run chmod -R 775 public

06 Nov
1 week ago
05 Nov
1 week ago

Sergiu17 left a reply on Pulling From Database

$amp = Listing::where('module', 'amp')->count();
$speakers = Listing::where('module', 'speakers')->count();
// etc

Sergiu17 left a reply on Pulling From Database

$amp = Listing::groupBy('modules')->select('modules', \DB::raw('count(*) as total'))->where('module', 'amp')->get();

$speakers = Listing::groupBy('modules')->select('modules', \DB::raw('count(*) as total'))->where('module', 'speakers')->get();

Sergiu17 left a reply on Guzzel POST Issue

Hi, if you did copy-paste, then, you have a syntax error

'password' => 1234' ,

should be

'password' => '1234' ,
04 Nov
1 week ago

Sergiu17 left a reply on Pagination Not Work

foreach ($data as $value) {
    return [
        'id' => $value->id,
        'question' => $value->translate('en')->question,
        'answer' => $value->translate('en')->answer,
    ];
}

No matter how many items $data contains, this loop will loop only one time. because you return :)

https://www.w3schools.com/php/default.asp :)

Sergiu17 left a reply on How To Stop Only Frontend Of App?

Open app\Http\Middleware\CheckForMaintenanceMode.php and there's

    protected $except = [
        '/admin',
        '/login'
    ];

You can add, /login, /admin and whatever you need

Sergiu17 left a reply on What's The Current Accepted 'best Practice' For Creating REST APIs?

Hi, if you are asking what to use from those 3 examples, the answer is, go with

Route::apiResource

There's nothing wrong to use

Route::get, ::post, etc

or you can use even resource

Route::resource('resource', 'ResourceController', [
    'except' => ['edit'] // except edit, create...
]);
02 Nov
2 weeks ago

Sergiu17 left a reply on Prevent Users From Accessing Search Api.

What about

if ( $request->filled('q') ) {
    // search query
    return $results;
}

return 'whatever you want';

Sergiu17 left a reply on Change Password Field On Edit My Profile Page

@munazzil lol, you definitely should be awarded :D

Sergiu17 left a reply on Beginner : Passed Var From Controller To A Vue

Every routes is connected to a view via callback or controller, let's take first example

Route::get('/', ['as' => 'home', function() { return view('home'); }]);
// here you return home.blade.php view, without any variable,
// so you can't say {{ $arch }} in home.blade.php
public function infos() {
    $arch = php_uname(); 
    $phpversion = phpversion();
    $mailAdmin = $_SERVER['SERVER_ADMIN'];

    // send to the home.blade.php view 3 variables, using compact
    return view('home',  compact('arch', 'phpversion', 'mailAdmin'));
    // or array as second parameter
    return view('home', [
        'arch' => $arch,
        'phpversion' => $phpversion,
        'mailAdmin' => $mailAdmin
    ]);
}
// here you have the function in controller, but do you have route that points to
// this function? And I know the answer, is NO!

Create new route

Route::get('/testing-info', '[email protected]')->name('infos');

And only now you can do in your view

{{ $arch }}

Sergiu17 left a reply on Pulling From Database

SELECT modules, count(*) FROM your_table group by modules;

Transform this query in Eloquent or use DB, but I'm 100% sure that this is the query you need

Sergiu17 left a reply on OnDelete('cascade') Vs. Using Model Events To Delete Records

Usually people first discover delete cascade, then they discover model events.

So better is to use onDelete('cascade'), because is at the database level. You don't need PHP for this, to do another query, delete them and all kind of stuff. Use delete cascade, my suggestion

01 Nov
2 weeks ago

Sergiu17 left a reply on How To Generate A Unique But Simple Id For Ticket?

I've found something on stackoverflow

hexdec(uniqid())

You can use this

Sergiu17 left a reply on Attach Array For All Views.

Is not a stupid question, read more about view composers - https://laravel.com/docs/5.7/views#view-composers

    public function boot()
    {
        // Using Closure based composers...
        // * ( star ) means send this variable to every view
        // can be: 'admin/*' - send variable to every view inside admin folder
        View::composer('*', function ($view) {
            $view->with('variable', 'value'); // example
            $view->with('menu', App\Menu::all());
        });
    }

Sergiu17 left a reply on Pulling From Database

Listing::groupBy('modules')->select('modules', DB::raw('count(*) as total'))->get();

Try this