Dry7

Member Since 1 Year Ago

Lipetsk

Certified Laravel Developer at Freelance

Experience Points 174,820
Experience Level 35

180 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 1506
Lessons
Completed
Best Reply Awards 38
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.

13 Jul
1 week ago

Dry7 left a reply on How To Add An Image Upload In The Form In Laravel

@michaelabraham use

$request->file('select_file')->store('avatars')
08 Jul
2 weeks ago

Dry7 left a reply on Pulling ID Into Form Within Modal

@mattb add game id to edit button

<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#editGame" data-id="{{ $game->id }}">Edit</button></td>

and add this javascript

$('#editGame').on('show.bs.modal', function (event) {
  var id = $(event.relatedTarget).data('id');  

  $(this).find('form').attr('action', 'pass your route here (without php) / ' + id);
})

Dry7 left a reply on Where To Place Redis Data Pull, Model Or Controller?

@xibel try to add new layer for this logic

class PostsRepository
{
    const SECONDS = 10;

    public function getPost(int $id)
    {
        return Cache::remember('posts.' . $id, self::SECONDS, function () use ($id) {
            return Post::query()->where('id', $id)->first();
        });
    }

    public function savePost(Post $post)
    {
        $post->save();
        Cache::put('posts' . $post->id, $post, self::SECONDS);
    }
}

Dry7 left a reply on How To Add An Image Upload In The Form In Laravel

@michaelabraham

public function store(Request $request)
    {
        Blog::create([
            'name' => $request->name,
            'message' => $request->message,
            'thumbnail' => $request->file('avatar')->store('avatars'),
        ]);
        return redirect()->back();
    }

and check what stored in thumbnail field

16 Sep
10 months ago

Dry7 left a reply on Cant Upload Single Image

@nhayder

$updateContent->poster = $request->file('poster')->store('posters');

Dry7 left a reply on File Upload Not Working

@aondoe can you provide code from controller?

01 Sep
10 months ago

Dry7 left a reply on Extending The App.blade Crashing My Date Picker Used In View.

@nagendrabhat


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$.noConflict();
</script>

...

<script type="text/javascript">
            jQuery(function ($) {
              $('.pickWeek').datetimepicker({
                  format: "YYYY-MM-DD",
                  sideBySide: true,
                  daysOfWeekDisabled: [0]
              });
              jQuery('#datetimepicker1').data('DateTimePicker').minDate(moment().startOf('week'));
              jQuery('#datetimepicker1').data('DateTimePicker').maxDate(moment().endOf('week'));
          });
      </script>

Dry7 left a reply on File Not Found For Download

@vkronlein you create

php artisan storage:link

Dry7 left a reply on Extending The App.blade Crashing My Date Picker Used In View.

@nagendrabhat Perhaps the problem is that the app uses the $ sign as well as the jQuery. try this approach https://api.jquery.com/jquery.noconflict/

27 May
1 year ago

Dry7 left a reply on Class 'App\Http\Controllers\Storage' Not Found

or app('filesystem')->delete($team->logo)

25 Mar
1 year ago

Dry7 left a reply on How To Call An Array Inside Another Array

@AquinoBR

@component('mail::button', ['url' => 'https://blockchain.info/tx/' . $content['url']])
22 Mar
1 year ago

Dry7 left a reply on Using Migrations Without Versioning?

@heykatieben this command will delete all data

21 Mar
1 year ago

Dry7 left a reply on Using Migrations Without Versioning?

@heykatieben If you already have data in the database, it is better to create a new migration for each change.

Dry7 left a reply on Save Value Of An Array

@copain delete

$this->validate($request, [
         
          'student_name'=>'required|max:50',
            
            
                ]);

Dry7 left a reply on Model Relation With Multiple Keys

@merisor yes, https://laravel.com/docs/5.5/eloquent-relationships#many-to-many like this

class Order extends Model
{
    function promotions() {
        return $this->belongsToMany('App\OrderItems', 'OrderPromotion', 'order_id', 'item_id')->withPivot('other_fields');
    }
}

Dry7 left a reply on Save Value Of An Array

@copain use cast https://laravel.com/docs/5.5/eloquent-mutators#array-and-json-casting

class Lead extends Model {
    protected $casts = [
        'student_name' => 'array',
        'age' => 'array',
        'gender' => 'array'
    ];
}
20 Mar
1 year ago

Dry7 left a reply on Update Dynamic Form Fields In Database (Insert/Delete)

@lara_net

foreach ((array)request('sub_code') {}
foreach ((array)$sub_codes as $i => $code) {}

Are there any Events in Laravel, that I can be tracked and fire once the user clicked 'Update' button?

https://laravel.com/docs/5.5/broadcasting

Dry7 left a reply on Update A File Input

@mcardosob Yes. only usually not only the list of deleted images is transferred to the server, but also the other data.

$.ajax({
    type: "PUT",
    url: "/client/3",
    data: {name: name, attachments_to_delete: attachments_to_delete},
    contentType: "json",
    success:function(data) {
        concsole.log(data.message)
    } 
});

Dry7 left a reply on Update A File Input

@mcardosob I usually use this practice. Or you can delete the file immediately after clicking on the button, with a separate ajax query.

Dry7 left a reply on Collection In Navbar.

@phpMick yes, just use them.

Dry7 left a reply on Mark All Fields From A Query

@richardh

PrivateMessage::where('recipient_id', '=', $request->authedUser->id)->update([
'read' => 1
])

Dry7 left a reply on Update Dynamic Form Fields In Database (Insert/Delete)

@lara_net try this code, I did not test it, but the meaning is correct and add jquery.

<form accept-charset="UTF-8" action="{{action('[email protected]', $id)}}" enctype="multipart/form-data" method="post" files="true">
<label>Student Name:</label> <input type="text"  name="name">
<label>Student Address:</label> <input type="text" name="name">
<label>Student Subject Feature</label>

@foreach($subjects as $sub)
<div class="sub">
<input type="text" name="sub_code[{{ $sub->id }}]" value="{{ $sub->sub_code }}" placeholder="Subject Code">
<input type="text" name="sub_name[{{ $sub->id }}]" value="{{ $sub->sub_name }}" placeholder="Subject Name">
<input type="file" name="sub_img[{{ $sub->id }}]">
<a href="javascript:deleteSub(this, {{ $sub->id }});" class="remove_field">Delete This Subject</a>
</div>
@endforeach
<button class="add_more">Add Subject</button>

<button type="submit">Update</button>

<script type="text/javascript">
function addSub()
{
    $('.add_more').prepend('<div class="sub">
<input type="text" name="new_sub_code[]" placeholder="Subject Code">
<input type="text" name="new_sub_name[]" placeholder="Subject Name">
<input type="file" name="new_sub_img[]">
<a href="javascript:deleteSub(this, 0);" class="remove_field">Delete This Subject</a>
</div>');
}

function deleteSub(el, id)
{
    if (Number(id) > 0) {
        $(el).parents('form').append('<input type="hidden" name="delete_sub[]" value="' + id + '" />');
    }
    $(el).parent().remove();
}
</script>
public function update(Request $request, $id){
  $stu=Students::FindOrFail($id)
  $subjects = Subjects::with(['subs'])->where('stu_id', $stu->id)->get();
  $stu->update($request->all());

  /** Old subjects */
  $sub_images = request()->file('sub_img');    
  $sub_names  = request('sub_name');
  foreach (request('sub_code') as $id => $code) {
    if(isset($sub_images[$i])) {
       $pathToStore = public_path('images');    
       if($request->hasFile('sub_img') && isset($sub_images[$i])) {
          $sub_img_name = uniqid() . '.' . $sub_images[$i]->getClientOriginalExtension();
           $sub_images[$i]->move(public_path('/images/'), $sub_img_name); 
           
           $sub = Subject::find($id);
           $sub->sub_code = $code;
           $sub->sub_name = $sub_names[$i];
           $sub->sub_img = "images/{$sub_img_name}";
           $sub->save();
           
      }
    }
  }

  /** New subjects */
  $sub_images = request()->file('new_sub_img');    
  $sub_names  = request('new_sub_name');
  $sub_codes  = request('new_sub_code');
  foreach ($sub_codes as $i => $code) {
    if(isset($sub_images[$i])) {
       $pathToStore = public_path('images');    
       if($request->hasFile('new_sub_img') && isset($sub_images[$i])) {
          $sub_img_name = uniqid() . '.' . $sub_images[$i]->getClientOriginalExtension();
           $sub_images[$i]->move(public_path('/images/'), $sub_img_name); 
           
           $sub = new Subject([
               'sub_code' => $code,
               'sub_name' => $sub_names[$i],
               'sub_img' => "images/{$sub_img_name}",
           ]);
           $sub->save();
           
      }
    }
  }

  /** Delete subjects */
  foreach (request('delete_sub') as $id) {
    Subject::find($id)->delete();
  }
}

Dry7 left a reply on Cron Job Scheduling

@ahmedyousuf create controller or/and route

Route::get('schedule', function() {
    Artisan::call('schedule:run');
});

and add this url in external cron - https://cron-job.org/en/

Dry7 left a reply on Required_if Validation Rule With Array Values.

@ravasaurio I think it's impossible through this validation rule. try to create your own validation rule https://laravel.com/docs/5.5/validation#custom-validation-rules

Dry7 left a reply on Fetch Auth::user()->name From Database

@Kaustubh you need to replace the name in the controller like this

$item = YourModel::find(1);
$item->output = str_replace('{!! auth::user()->name !!}', Auth::user()->name, $item->output);
return $item->output;

{!! auth::user()->name !!} can be replaced by something like #NAME#

21 Feb
1 year ago

Dry7 left a reply on PHP Refactoring: Function Aliases? Need Opinions.

@godbout http://php.net/manual/en/language.oop5.overloading.php

class YourClass {
public function __call($name, $arguments)
    {
    }
}
17 Feb
1 year ago

Dry7 left a reply on Validation

@Farouz

$validator = Validator::make($request->all(), [
    'oldPassword' => [
        'required',
        'max:255',
        function($attribute, $value, $fail) use ($user) {
            if (bcrypt($value) !== $user->password) {
                return $fail($attribute.' is invalid.');
            }
        },
    ],
]);

Dry7 left a reply on How To Use Old() In Multiple Select Without Using Form::select()

@oroalej

<select name="categories[]">
    <option value="test"{!! in_array('test', old('categories')) ? ' selected' : '' !!}>Test</option>
</select>

validation: you can use Custom Validation Rules https://laravel.com/docs/5.6/validation#custom-validation-rules

Dry7 left a reply on How Can I Pass Parameter In Route Href={{Route('test'./$val}} To Blade View?

@Webiondev123

<p><a href={{route('test', $id)}}" class="btn btn-info btn-xs" role="button">know more</a> 

Dry7 left a reply on How To Make Json : Previous, Next On Detail Page

@mipusy

return Response()->json([
    'article' => $article,
    'previous' => $previous,
    'next' => $next
]);
14 Jan
1 year ago

Dry7 left a reply on Add Validation To Repeater Field

@GregorSams https://laravel.com/docs/5.5/validation#validating-arrays try

        $this->validate($request, [
            'team.*.firstName' => 'nullable|min:2|max:190',
            'team.*.lastName' => 'nullable|min:3|max:190',
            'team.*.twitter' => 'nullable|min:3|max:190',
            'team.*.userName' => 'required|min:1|max:190',
        ]);
15 Dec
1 year ago

Dry7 left a reply on FirstOrCreate/New With MySQL Operators

@bcharron No, I think the check should be done manually

02 Dec
1 year ago

Dry7 left a reply on 5.5 Point Type Column

@wildwestriverrider I found only this method

DB::statement('UPDATE table SET column = POINT(?, ?) WHERE id=?', [111, 222, 1]);

Dry7 left a reply on Laravel 5.5 Model Pivot Table Count

@afoysal

class Gallery extends Model {
    public function blogs()
    {
        return $this->belongsToMany('App\Models\Blog');
    }
}

and use https://laravel.com/docs/5.5/eloquent-relationships#counting-related-models or just

$gallery->blogs->count()
29 Nov
1 year ago

Dry7 left a reply on How To Structure The JSON Response With Selected Values From A Collection?

@gianpiero.addis try like this

LogbookEntry::whereMonth('visited_at', $month) // Just a dummy time constraint
    ->selectRaw('DAY(visited_at) as day, patron_category_id, count(*) as visits')
    ->with('patronCategory:id,name')
    ->groupBy('patron_category_id', 'day')
    ->orderBy('day')
    ->get()
    ->map(function ($entry) {
        return collect($entry->toArray())
        ->only(['day', 'visits', 'patron_category'])
        ->all();
    })->flatMap(function ($values) {
        $days = [];
        foreach ($values as $value) {
            if (!isset($days[$value->day)) { $days[$value->day] = []; }
            $days[$value->day][$value->patron_category->name] = $value->visits;
        }
        return $days;
    });
28 Nov
1 year ago

Dry7 left a reply on Task Scheduler Works On Homestead, But Not On Shared Hosting

@patrikw1 may a typo in crontab? try sending an email to yourself in one of these commands

Dry7 left a reply on May I Know..? What Command Should Add When I Am Upload My Crone Job Laravel Project To The Server..?

@vengateshwaran add to cron (crontab -e)

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

and in app/Console/Kernel.php like this https://github.com/Dry7/crm_catering/blob/develop/app/Console/Kernel.php

Dry7 left a reply on Dynamic Properties For Relations Return Null

@SevenOutman what returns

$user->primary_receiver

?

27 Nov
1 year ago

Dry7 left a reply on Problem With Installing Laravel

@sasr22 you have a folder database/seeds?

Dry7 left a reply on Updating Model With Relationships In A Single Request

@falnyr https://laravel.com/docs/5.5/eloquent-relationships#inserting-and-updating-related-models try

$post->saveMany(
    collect($request->get('tags'))->map(function ($tag) { return new Tag($tag); })->toArray()
);

Dry7 left a reply on Multiple Call To Actions On Notifications

@Bartude run

php artisan vendor:publish --tag=laravel-notifications

and add second button manually