Dry7

Certified Laravel Developer at Freelance

Hire Me

Experience

148,440

40 Best Reply Awards

  • Member Since 8 Months Ago
  • 1245 Lessons Completed
  • 0 Favorites

25th March, 2018

Dry7 left a reply on How To Call An Array Inside Another Array • 1 month ago

@AquinoBR

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

22nd March, 2018

Dry7 left a reply on Using Migrations Without Versioning? • 1 month ago

@heykatieben this command will delete all data

21st March, 2018

Dry7 left a reply on Using Migrations Without Versioning? • 1 month ago

@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 • 1 month ago

@copain delete

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

Dry7 left a reply on Model Relation With Multiple Keys • 1 month ago

@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 • 1 month ago

@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'
    ];
}

20th March, 2018

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

@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 • 1 month ago

@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 • 1 month ago

@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. • 1 month ago

@phpMick yes, just use them.

Dry7 left a reply on Mark All Fields From A Query • 1 month ago

@richardh

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

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

@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 • 1 month ago

@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. • 1 month ago

@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 • 1 month ago

@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#

21st February, 2018

Dry7 left a reply on PHP Refactoring: Function Aliases? Need Opinions. • 2 months ago

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

class YourClass {
public function __call($name, $arguments)
    {
    }
}

17th February, 2018

Dry7 left a reply on Validation • 2 months ago

@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() • 2 months ago

@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? • 2 months ago

@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 • 2 months ago

@mipusy

return Response()->json([
    'article' => $article,
    'previous' => $previous,
    'next' => $next
]);

14th January, 2018

Dry7 left a reply on Add Validation To Repeater Field • 3 months ago

@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',
        ]);

15th December, 2017

Dry7 left a reply on FirstOrCreate/New With MySQL Operators • 4 months ago

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

2nd December, 2017

Dry7 left a reply on 5.5 Point Type Column • 4 months ago

@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 • 4 months ago

@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()

29th November, 2017

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

@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;
    });

28th November, 2017

Dry7 left a reply on Task Scheduler Works On Homestead, But Not On Shared Hosting • 4 months ago

@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..? • 4 months ago

@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 • 4 months ago

@SevenOutman what returns

$user->primary_receiver

?

27th November, 2017

Dry7 left a reply on Problem With Installing Laravel • 4 months ago

@sasr22 you have a folder database/seeds?

Dry7 left a reply on Updating Model With Relationships In A Single Request • 4 months ago

@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 • 4 months ago

@Bartude run

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

and add second button manually

Dry7 left a reply on Reseting The Mysql Password On A Homestead Box • 4 months ago

@Leff7 Homestead usually uses a homestead user, try

mysqladmin -u homestead -p password

Dry7 left a reply on Realtion In Pivot Table • 4 months ago

@mdeorue use

return $this->belongsToMany('App\Model')->withPivot('player_positions');
$user = App\User::find(1);

foreach ($user->roles as $role) {
    echo $role->pivot->player_positions;
}

If this does not help, then show your code

Dry7 left a reply on Dropdown In Laravel • 4 months ago

@anp24 Controller

class TestController extends Controller
{
    public function index()
    {
        return view('form')
            ->with('options', [
                'First',
                'Second',
                'Third'
            ]);
//        return view('form')->with('options', YouModel::all());
    }
}

/resources/views/form.blade.php

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script>
  $(document).ready(function() {
    $('select').select2();
});
</script>

<select name="test" multiple="multiple">
    @foreach($options as $option)
        <option value="{{ $option }}">{{ $option }}</option>
    @endforeach
</select>

Dry7 left a reply on Android With Laravel ??? • 4 months ago

@angelz.gutierrez just develop the app and then call an api

Dry7 left a reply on Implemented Chart Do Not Show • 4 months ago

@MatusVrsansky or use window.onload

<script>
window.onload = function() {
    var canvasP = document.getElementById("pieChart");
var ctxP = canvasP.getContext('2d');
var myPieChart = new Chart(ctxP, {
   type: 'pie',
   data: {
      labels: ["Värde 1", "Värde 2", "Värde 3", "Värde 4", "Värde 5", "Värde 6", "Värde 7"],
      datasets: [{
         data: [1, 5, 10, 20, 50, 70, 50],
         backgroundColor: ["#64B5F6", "#FFD54F", "#2196F3", "#FFC107", "#1976D2", "#FFA000", "#0D47A1"],
         hoverBackgroundColor: ["#B2EBF2", "#FFCCBC", "#4DD0E1", "#FF8A65", "#00BCD4", "#FF5722", "#0097A7"]
      }]
   },
   options: {
      legend: {
         display: true,
         position: "right"
      }
   }
});

canvasP.onclick = function(e) {
   var slice = myPieChart.getElementAtEvent(e);
   if (!slice.length) return; // return if not clicked on slice
   var label = slice[0]._model.label;
   switch (label) {
      // add case for each label/slice
      case 'Värde 5':
         alert('clicked on slice 5');
         window.open('www.example.com/foo');
         break;
      case 'Värde 6':
         alert('clicked on slice 6');
         window.open('www.example.com/bar');
         break;
      // add rests ...
   }
}
  };
</script>

Dry7 left a reply on Implemented Chart Do Not Show • 4 months ago

@MatusVrsansky try to transfer the library above the code

<!DOCTYPE html>
<head>


</head>

<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script>
var canvasP = document.getElementById("pieChart");
var ctxP = canvasP.getContext('2d');
var myPieChart = new Chart(ctxP, {
   type: 'pie',
   data: {
      labels: ["Värde 1", "Värde 2", "Värde 3", "Värde 4", "Värde 5", "Värde 6", "Värde 7"],
      datasets: [{
         data: [1, 5, 10, 20, 50, 70, 50],
         backgroundColor: ["#64B5F6", "#FFD54F", "#2196F3", "#FFC107", "#1976D2", "#FFA000", "#0D47A1"],
         hoverBackgroundColor: ["#B2EBF2", "#FFCCBC", "#4DD0E1", "#FF8A65", "#00BCD4", "#FF5722", "#0097A7"]
      }]
   },
   options: {
      legend: {
         display: true,
         position: "right"
      }
   }
});

canvasP.onclick = function(e) {
   var slice = myPieChart.getElementAtEvent(e);
   if (!slice.length) return; // return if not clicked on slice
   var label = slice[0]._model.label;
   switch (label) {
      // add case for each label/slice
      case 'Värde 5':
         alert('clicked on slice 5');
         window.open('www.example.com/foo');
         break;
      case 'Värde 6':
         alert('clicked on slice 6');
         window.open('www.example.com/bar');
         break;
      // add rests ...
   }
}
</script>



<canvas id="pieChart"></canvas>

</body>
</html>

26th November, 2017

Dry7 left a reply on Customise Email Notifications? • 4 months ago

@cyberfountain run

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

After running this command, the mail notification templates will be located in the resources/views/vendor/notifications directory.

Dry7 left a reply on How To Add Html Tag In Json Tranlation File • 4 months ago

@sibarra@browns.edu.au

{!! __('Hello :user, How are you ?', ['user' => $guest]) !!}

should work. or try

{!! htmlspecialchars_decode(__('Hello :user, How are you ?', ['user' => $guest])) !!}

25th November, 2017

Dry7 left a reply on SQL To Eloquent -- How To Convert This Query? • 5 months ago

@sergionader use selectRaw

$sql = DB::table('visits')
        ->join('product_visit', 'visit_id', '=', 'visits.id')
        ->where('product_visit.amount', '>', 0)
        ->whereBetween('visits.dt', [$dt_start, $dt_start])
        ->groupby('month_idx', 'year')
        ->groupby(['year', 'desc'])
        ->selectRaw(
            'DATE_FORMAT(visits.dt, \'%m\') AS month_idx',
            'DATE_FORMAT(visits.dt, \'%b\') AS month',
            'DATE_FORMAT(visits.dt, \'%Y\') AS year',
            'ROUND(sum(product_visit.amount)) AS y'
        )
        ->get();

24th November, 2017

Dry7 left a reply on Laravel +postgresql Groupby Query • 5 months ago

@imtiyaz004

Package::where('type', 'domestic')->groupBy('state')
but the original query is incorrect, it is worth writing

Package::select('state')->where('type', 'domestic')->groupBy('state')

13th November, 2017

Dry7 left a reply on Laravel.log Could Not Be Opened: Failed To Open Stream: Permission Denied • 5 months ago

@dohisev try

chmod 777 /storage/logs/laravel.log

10th November, 2017

Dry7 left a reply on Laravel Multiple Image View • 5 months ago

@mhhiron123 just a cycle. but if the question is how to display some picture stored in the database, then more details are needed, how it is stored, how it is added.

Dry7 left a reply on Display More Than One Tag On Views • 5 months ago

@helpmyworld check the html source code, maybe the reason in css.

Edit Your Profile
Update

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