Sergiu17

Experience

179,950

86 Best Reply Awards

  • Member Since 1 Year Ago
  • 1205 Lessons Completed
  • 12 Favorites

24th September, 2018

Sergiu17 left a reply on How To Fire An Event In <v-autocomplete> Component • 1 day ago

There @keyup

// basic example 
<input @keyup="search">

Sergiu17 left a reply on Why UserNotVerifiedException Error Is Not Trigered? • 2 days ago

// routes/web.php

Auth::routes(['verify' => true]);

Did you set to true verify route?

23rd September, 2018

Sergiu17 left a reply on How To Generate Csv File And Send Email As Attachment With Cronjob In Laravel? • 2 days ago

@HopesAreMiracle Here is the documentation https://laravel.com/docs/5.7/mail

When you send a mail - you actually use a view, blade view for it. So, in your case you have to create a view for the email with some text and attached file. Hope you understand, if not - read documentation, very well explained there

22nd September, 2018

Sergiu17 left a reply on Allow Users To Update HTML Content? • 3 days ago

what if he add another menu link?

Store menu in the database

21st September, 2018

Sergiu17 left a reply on When The User Upload New Image I Want To Delete The Previous Image In Folder • 4 days ago

Easy staff

public function update(Request $request, $id) {
    
    $user = $user->findOrFail($id);

    if ($request->has('image') {
        if(file_exists('/images/ . $user->image) {
            unlink('/images/ . $user->image);
        }

        $request->image->move('/images', $request->image->getClientOriginalName());

        $user->image = $request->image->getClientOriginalName();
    }

    $user->save();
}

Basic example

Sergiu17 left a reply on Why UserNotVerifiedException Error Is Not Trigered? • 4 days ago

Does your User model implements MustVerifyEmail interface?

Sergiu17 left a reply on File Management • 4 days ago

if ( is_dir('directory name') ) { echo 'True'; } // if is directory
mkdir('/path/to/my/dir', 0777); // make directory with 777 permissions 

Sergiu17 left a reply on Get Items WHERE Condition Is A Related/joined Table • 4 days ago

@RafaelMunoznl ohh, skipped semicolon at second line

$quety->orderBy('film_id', 'desc'); <---- add semicolon

Sergiu17 left a reply on Get Items WHERE Condition Is A Related/joined Table • 4 days ago

Film::whereHas(['reviews' => function ($query) {
    $quety->orderBy('reviews.film_id', 'desc')
}])->get();

Does this work?

Sergiu17 left a reply on How To Generate Csv File And Send Email As Attachment With Cronjob In Laravel? • 5 days ago

$filename = public_path() . '\reports\tweets.csv';

Delete this return Response::download($filename, 'tweets.csv', $headers);

Generate new Mail with

php artisan make:mail TweetsMail
<?php

namespace App\Mail;

use App\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class TweetsMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Path to CSV
     *
     * @var Path
     */
    protected $path;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(string $path
    {
        $this->path = $order;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.view');
                    ->attach($this->path);
    }
}

Now, instead of return Download, send an email

Mail::to('[email protected]')->send(new TweetsMail($path));

I did some copy-paste from documentation and modified it, hope I didn't skip

Sergiu17 left a reply on How To Generate Csv File And Send Email As Attachment With Cronjob In Laravel? • 5 days ago

You can't without saving it, you have to attach the file to the email.

How do you send emails?! Show your cron job's code

Sergiu17 left a reply on How To Generate Csv File And Send Email As Attachment With Cronjob In Laravel? • 5 days ago

return $this->view('emails.report')
                    ->attach('/path/to/file');

When you create a that CSV File, you have path for him right?! you save it somewhere, now just pass that path to attach function.

Sergiu17 left a reply on Vue SPA, Ajax And Laravel -> MethodNotAllowedHttpException • 5 days ago

Install Postman and start debugging, could you show where do you send the request? In Developer Tools in Browser, there's Network Tab, open in and see what's there.

Sergiu17 left a reply on Searchable Arrays In Database • 5 days ago

I don't know what Website Model is, but I know that you need one more many to many relationship between Topics and News

New Has Many Topics

Topic Has Many News

Sergiu17 left a reply on Catch Php File Not Found Exception • 5 days ago

public function render($request, Exception $exception)

{

if(`$e` instanceof \Illuminate\Contracts\Filesystem\FileNotFoundException) {

    abort(404);


}

}

May be here is the problem?!

public function render($request, Exception $exception)
{
    if(`exception instanceof \Illuminate\Contracts\Filesystem\FileNotFoundException) {

Sergiu17 left a reply on Searchable Arrays In Database • 5 days ago

This is classic Many To Many Relationship,

User Has Many Subscribe Topics

Subscribe Topics Has Many Users

20th September, 2018

Sergiu17 left a reply on DB Query And Export On Button Click. • 5 days ago

@Naraa

public function gradeExport() {
    $records = DB::raw() ...

    $file = fopen(public_path() . '\report.csv', 'w');

    foreach ($records as $record) {
        $line = [$record->RatedName, $record->RaterName, $record->RoundsTitle, $record->SkillsTitle, $record->Rating, "\n"];
        fputcsv($file, $line);
        }

    fclose($file);

    return response()->download(public_path() . '\report.csv');
}

Like so! I've tested this.

Sergiu17 left a reply on How To Manage ProductsController And ImagesController From The Same Form? • 5 days ago

Usually what I do is I create a Service for uploading images.

<?php
namespace App\Services;

class Image
{
    public function upload($image)
    {
        // code to upload image
    }
}
<?php

use App\Services\Image;

class ProductsController extends Controller
{
    protected $image;
    
    public function __construct(Image $image)
    {
        $this->image = $image;
    }

    public function store(Request $request)
    {
        // save product

        if($request->hasFile('images')) {
            $this->image->upload($reuqest->images);
        }
    }
}

You may like this approach :)

Sergiu17 left a reply on Route:list Outputting Strange Characters • 5 days ago

@BGWeb your terminal doesn't support ANSI colors, just read an article about it, see some examples http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html

Sergiu17 left a reply on Twisting Model::all() • 5 days ago

Model::orderBy('column')->get();

Model::orderByDesc('column')->get();

Sergiu17 left a reply on Route:list Outputting Strange Characters • 5 days ago

php artisan route:list --no-ansi

Does this solve your problem?!

Sergiu17 left a reply on Automatically Model Binding The Logged In User • 5 days ago

You don't need a parameter for this

Route::get ( "/users/me/conversations" , "[email protected]" );
class ConversationController extends Controller
{
    public function __construct() 
    {
        $this->middleware('auth');
    }

    public function index ()
    {
        return auth()->user()->conversations;
    }
}

If user is logged in, index method will return, otherwise middleware from constructor will take care of it and will redirect to login page!

Sergiu17 left a reply on Automatically Model Binding The Logged In User • 5 days ago

Route::get ( "/users/{id}/conversations"

public function index ( User $id )

Route::get ( "/users/{user}/conversations"

public function index ( User $user )

Route::get ( "/users/{profile}/conversations"

public function index ( User $profile )

Placeholder should match to variable name from parameter

Sergiu17 left a reply on DB Query And Export On Button Click. • 5 days ago

$records = DB::raw( ... ;

$file = fopen('report.csv', 'w');

foreach ($records as $record)
{
    fputcsv($record, explode(',', $line));
}


fclose($file);

return response()->download('report.csv');

As easy as that!

Sergiu17 left a reply on Read A Relationship Based Value In Where Clause • 6 days ago

<script>
fetch('/lessons').then(function(response) {
    console.log(response);
})
</script>

I think you need `window.lessons = response.data'

Just start debugging

19th September, 2018

Sergiu17 left a reply on Read A Relationship Based Value In Where Clause • 6 days ago

@dabnad

Route::get('/lessons', function() {
    return App\Lesson::where('isCancel', 0)->get();
});
<script>

</script>

fetch('/lessons').then(function(response) { window.lessons = response; })


Just use an AJAX Request for this, much elegant and eloquent ))

Sergiu17 left a reply on Reactjs & Laravel - How To Combine Reactjs Project With Laravel ? • 1 week ago

As I know ( maybe I'm wrong ) React is Fully SPA, so in your case, you create separately a Laravel App which will provide API End Points for your React App

Sergiu17 left a reply on One To Many Definition And Foreign Key • 1 week ago

Of course go with foreign key, read definition - https://en.wikipedia.org/wiki/Foreign_key

return $this->hasMany(Comment::class);

Go with this approach, result is the same, but IDE understands it better, in PHPStorm when you CTRL+CLICK on Comment class, it redirects to Comment class

18th September, 2018

Sergiu17 left a reply on Read A Relationship Based Value In Where Clause • 1 week ago

Extending @mikeRees answers

$userId =  2;
Actors::whereHas('users', function ($query) use ($userId) {
    $query->where('ReadMe', $userId);
})

Because you want to use dynamic value there.

16th September, 2018

Sergiu17 left a reply on Software Architecture • 1 week ago

Hard staff! ( at least in my thoughts ) and bit topic, no one is going to explain you what is software architecture, because it's a huge! And you can't learn this is few days/weeks, it requires years of experience!

15th September, 2018

Sergiu17 left a reply on Help With Git • 1 week ago

Yes, you have to reinstall all the dependencies again. Because .gitignore file, ignores vendor directory. Learn more about CI/CD.

13th September, 2018

Sergiu17 left a reply on How To Query A 1-to-many Relation , Selecting And Filtering On Both Table? • 1 week ago

Name::with(['addresses' => function($query) {
    $query->where('address_text_field', 'like', ''%something%')->select('filed1', 'field2');
})->get('field1', 'field2');

I guess it should work

12th September, 2018

Sergiu17 left a reply on __() Translation • 1 week ago

https://laravel.com/docs/5.7/localization - documentation is your best friend, give you a hint, first paragraph

Sergiu17 left a reply on Console.log Not Working • 1 week ago

$("#communicated-teachers-forms").click(function (event) {
    event.preventDefault();
    console.log('test');

    // ajax

When you click on the button, preventDefault, console log and send ajax request

Sergiu17 left a reply on Correct Approach To Import Data Into Mysql From Large Csv. (rows > 100k) • 1 week ago

http://php.net/manual/en/language.generators.overview.php

Calling range(0, 1000000) will result in well over 100 MB of memory being used.

As an alternative, we can implement an xrange() generator, which will only ever need enough memory to create an Iterator object and track the current state of the generator internally, which turns out to be *less than 1 kilobyte.

http://mark-story.com/posts/view/php-generators-a-useful-example http://www.sebastianviereck.de/en/ver-abreiten-large-files-with-php-using-generator/

Hope this example will help you, short answer is: use generators!

Sergiu17 left a reply on How To Use Registration Form For Two Tables • 1 week ago

$company = Company::create($requeste->all());

User::create([
    'company_id' => $company->id,
]);

As easy as that. I wrote less code because I'm from mobile. Hope you understand!

Sergiu17 left a reply on How To Use Registration Form For Two Tables • 1 week ago

bcrypt is a helper function ( we call them 'wrapper' ) which calls make method from Hash facade.

To see all helper functions: vendor/laravel/framework/src/Illuminate/Foundation/helpers.php search for bcrypt function

Sergiu17 left a reply on Dompdf Mail With Attachment • 1 week ago

Route::get('/quotations/{quotation}/edit');
public function edit(Quotation $quotation)
{

$quotation should match with placeholder between { }

// if route
Route::get('quotations/{quotation}/edit');
public function edit(Quotation $quotation) { ... }

// if route
Route::get('quotations/{id}/edit');
public function edit(Quotation $id) { ... }

// if route
Route::get('quotations/{slug}/edit');
public function edit(Quotation $slug { ... }

Did you get it? hope this is the problem

Sergiu17 left a reply on How To Use Registration Form For Two Tables • 2 weeks ago

Company::create($request->all()); // -> this is mass assignment

// now let's say your fillable array is
class Company extends Model {
    $fillable = ['name', 'email'];
}

// This means, Company model allows only name and email to insert into database.
// Why this? Because $request may contain data which you don't need.
// alternative way, for this you don't need fillable array
$company = new Company();
$company->email = $request->email;
$company->phone_number = $reuqest->phone_number;
$company->save();
// this is manual way

11th September, 2018

Sergiu17 left a reply on Dompdf Mail With Attachment • 2 weeks ago

<form action="{{ route('name', $quotation->id) }}" method="post">
@csrf @method('PATCH')

Sending $quotation->id or $quotation->slug as a second parameter is very important!

Sergiu17 left a reply on How To Use Registration Form For Two Tables • 2 weeks ago

public function store(Request $request) {
    User::create([
        'name' => $request->company_name,
        'email' => $request->email_id,
        'password' => Hash::make($request->phone_number),
    ]);
    
    Company::create([
        'name' => $request->company_name,
        'type' => $request->company_type,
        'description' => $request->description,
        'address' => $request->address,
        'email' => $request->email_id,
        'phone' => $request->phone_number,
        'logo' => $logoName,
    ]);
}

Like so, make sure you validate them, and don't forget about $fillable array in Company model

Sergiu17 left a reply on Route With Names Issue • 2 weeks ago

When you return your view, do you pass $channelTest variable?

9th September, 2018

Sergiu17 left a reply on Append The Search Result In The Input Search Field • 2 weeks ago

@petrir Vue is two way binding, if you change the value of the input, it automatically changes the value of the variable

Sergiu17 left a reply on Append The Search Result In The Input Search Field • 2 weeks ago

new Vue({
    el: '#app',

    data: {
        search: ''
    },

    methods: {
        action(id) {
            this.search += id;
        }
    }
});

If I understood you

8th September, 2018

Sergiu17 left a reply on What Theme/Color-Scheme Is Jeffery Way Using Laravel 5.7 • 2 weeks ago

@JeffreyWay, you should start a new series "Color Themes I Use"

7th September, 2018

Sergiu17 left a reply on First Laravel Project .... • 2 weeks ago

@MikeLeeds Laravel mix does this for you

Sergiu17 left a reply on Failed Asserting That False Is True !!! • 2 weeks ago

phpunit --filter user_can_update_serie

run this, make sure this test fails

Sergiu17 left a reply on First Laravel Project .... • 2 weeks ago

No, no, no! Write your CSS in resources/sass/app.scss and run

npm run production

This command will minify output

Sergiu17 left a reply on Is There A Way To Format Money In Blade? • 2 weeks ago

use PHP function money_format

// http://php.net/manual/en/function.money-format.php

@php $number = 1234.56; @endphp // skip this

// let's print the international format for the en_US locale
@php setlocale(LC_MONETARY, 'en_US'); @endphp // skip this too, just for example
{{ money_format('%i', $number) }}
// USD 1,234.56
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.