Dry7

Developer at Freelance

Hire Me

Experience

143,040

33 Best Reply Awards

  • Member Since 5 Months Ago
  • 1231 Lessons Completed
  • 0 Favorites

17th February, 2018

Dry7 left a reply on Validation • 4 days 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() • 4 days 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? • 4 days 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 • 4 days ago

@mipusy

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

14th January, 2018

Dry7 left a reply on Add Validation To Repeater Field • 1 month 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 • 2 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 • 2 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 • 2 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? • 2 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 • 2 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..? • 2 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 • 2 months ago

@SevenOutman what returns

$user->primary_receiver

?

27th November, 2017

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

@sasr22 you have a folder database/seeds?

Dry7 left a reply on Updating Model With Relationships In A Single Request • 2 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 • 2 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 • 2 months ago

@Leff7 Homestead usually uses a homestead user, try

mysqladmin -u homestead -p password

Dry7 left a reply on Realtion In Pivot Table • 2 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 • 2 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 ??? • 2 months ago

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

Dry7 left a reply on Implemented Chart Do Not Show • 2 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 • 2 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? • 2 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 • 2 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? • 2 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 • 2 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 • 3 months ago

@dohisev try

chmod 777 /storage/logs/laravel.log

10th November, 2017

Dry7 left a reply on Laravel Multiple Image View • 3 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 • 3 months ago

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

8th November, 2017

Dry7 left a reply on Question About Database Design For Product Orders • 3 months ago

@PaulDiamant It is better to save prices in the orders_products , because the price can change, and the user will be surprised.

8th October, 2017

Dry7 left a reply on How To Create Table Relationship In Laravel • 4 months ago

@Flex foreign key name

7th October, 2017

Dry7 left a reply on How To Create Table Relationship In Laravel • 4 months ago

@ftrillo you can use both methods

Dry7 left a reply on How To Create Table Relationship In Laravel • 4 months ago

@Flex try

Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('project_id', false, true)->index()->comment = 'Project';
            $table->integer('task_id', false, true)->nullable(); //Parent task, if exists
            $table->string('name')->nullable()->comment = 'Название';

            $table->foreign('project_id', 'fk__tasks__project_id')
                ->references('id')
                ->on('projects')
                ->onDelete('cascade');
            $table->foreign('task_id', 'fk__tasks__task_id')
                ->references('id')
                ->on('tasks')
                ->onDelete('cascade');
        });

So your models will work. In order to create a subtask, simply fill in the task_id field

Dry7 left a reply on Trouble Accessing An Array • 4 months ago

@gregghoush maybe

$visits = $visits['subtable'][0];

?

Dry7 left a reply on Problem With Accessing Local Symbolic Link In Storage • 4 months ago

@JanakaDombawela try

{{ Storage::url('2017/10/file.txt') }}}

6th October, 2017

Dry7 left a reply on ErrorException (E_NOTICE) Undefined Index: Month • 4 months ago

@imposition try

$blogs = Blog::latest()
        ->filter(request()->only(['month', 'year']))
        ->get();
        if (isset($filters['month'])) {

            $query->whereMonth('created_at', Carbon::parse($filters['month'])->month);
        }
        
        if (isset($filters['year'])) {

            $query->whereYear('created_at', $filters['year']);
        }

5th October, 2017

Dry7 left a reply on MethodNotAllowedHttpException No Message • 4 months ago

@Geoff_256 try

{!! Form::model($auditor, ['method'=>'POST', 'route' => ['auditor.update', $auditor->id]]) !!}

Dry7 left a reply on How To Delete Post_tags And Tag In A Same Instruction • 4 months ago

@Lina use foregin keys in migration (and db) and everything will happen automatically

Schema::create('post_tags', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('tag_id', false, true);
            $table->integer('post_id', false, true);

            $table->foreign('tag_id', 'fk__post_tags__tour_tag_id')
                ->references('id')
                ->on('tags')
                ->onDelete('cascade');
            $table->foreign('post_id', 'fk__post_tags__post_id')
                ->references('id')
                ->on('posts')
                ->onDelete('cascade');
        });

28th September, 2017

Dry7 left a reply on How To Add Where Condition On Laravel Blade? • 4 months ago

@wardaddy try

@if (Auth::user()->type_id == 1) //Admin
showing <a href="#">Add Channel</a>
@elseif (Auth::user()->type_id == 2) //DJ
showing <a href="#">Add Channel</a>
@else //Guest
@endif 

18th September, 2017

Dry7 left a reply on MODEL->save() Error • 5 months ago

@TomyLimon show Document class

Dry7 left a reply on Laravel Beautymail • 5 months ago

@salomon022 add in header

use Snowfire\Beautymail\Beautymail;

Dry7 left a reply on How To Send Array From Script To Controler • 5 months ago

@hecate0211 use

data: JSON.stringify(data),

in $.ajax

17th September, 2017

Dry7 left a reply on Cache A Single Post? Cache And Pagination? • 5 months ago

@ronon

$id = 1;
$post = Cache:rembemer('posts.' . $id, 60, function() use ($id) {
    return Post::find($id);
});
  1. no, you need to make separate requests for each page

Dry7 left a reply on How To Show Table Data Regarding To Id • 5 months ago

@Flex you need to use the task_id in the comments table instead of the project_id in Task model

public function comments()
{
   return $this->hasMany('App\Comment');
}

and just use foreach($task->comments) in view

16th September, 2017

Dry7 left a reply on How To Send Array From Script To Controler • 5 months ago

@hecate0211

public function saveJson(Illuminate\Http\Request $request)
        {
            $data = json_decode($request->getContent());

        }

or

use Illuminate\Http\Request; (in header)

public function saveJson($request)
        {
            $data = json_decode($request->getContent());
        }

Dry7 left a reply on How To Send Array From Script To Controler • 5 months ago

@hecate0211

  1. in view
<script type="text/javascript">
                        function sendData() {
                            var data = [
                                1,
                                2,
                                3
                            ];
                            $.ajax({
                                url:'/test',
                                type: 'POST',
                                dataType:'json',
                                contentType: 'json',
                                data: JSON.stringify(data),
                                contentType: 'application/json; charset=utf-8',
                            });
                        }
</script>
  1. in controller
function saveJson(Illuminate\Http\Request $request)
{
    $data = json_decode($request->getContent());
}
  1. in app\Http\Middleware\VerifyCsfrToken
protected $except = [
        '/url-of-saveJson'
    ];

Dry7 left a reply on How Can I Insert Multi Rows In A Single Query? • 5 months ago

@mohammad_h73

$data = [
    [
        'field1'    => 'a',
        'field2'    => 'b',
    ],
    [
        'field1'    => 'c',
        'field2'    => 'd',
    ],
];

foreach ($data as $row) {
    Model::create($row);
}

or
collect($data)->each(function ($item) { Model::create($item)l });
Edit Your Profile
Update

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