s4muel

Experience

41,380

12 Best Reply Awards

  • Member Since 1 Year Ago
  • 342 Lessons Completed
  • 5 Favorites

15th October, 2018

s4muel left a reply on Laravel Update Record With AJAX • 6 days ago

do you have the token in html meta tag?

<meta name="csrf-token" content="{{ csrf_token() }}">

s4muel left a reply on Scheduling Auto Email • 6 days ago

have a look at https://laravel.com/docs/5.7/scheduling

bonus: there is an older video for task scheduling, but lot of advice there https://laracasts.com/series/intermediate-laravel/episodes/1

s4muel left a reply on Get Data From One To Many Relatioship • 6 days ago

you have a typo:

return $this->belongsTo('App\Models\Videos\VideoCategory'.'category_id'); //dot is here instead of a comma

9th October, 2018

s4muel left a reply on Request Sometimes Null • 1 week ago

you say:

...The Ajax request has two post variables: question_id, answer.... you mean question_id? because in the store() method, you use:

'question_id' => request('question'), //'question' is used as the parameter request helper

might this be the cause?

s4muel left a reply on Remove Class • 1 week ago

s4muel left a reply on Remove Class • 1 week ago

document.querySelector('.here').previousElementSibling.classList.remove('press')

8th October, 2018

s4muel left a reply on Default Index Order • 1 week ago

either order them before passing to a view, or use a global scope that applies on the model and let you order your items, https://laravel.com/docs/5.7/eloquent#global-scopes

there is also an Anonymous Global Scope that you can use like this (as from the documentation):

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class User extends Model
{
    /**
     * The "booting" method of the model.
     *
     * @return void
     */
    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('age', function (Builder $builder) {
            $builder->where('age', '>', 200);
        });
    }
}

just replace the age filter with your desired sorting

6th October, 2018

s4muel left a reply on Developing Relationship Between Users As "Connections" • 2 weeks ago

hm, try it this way:

public function getConnectionsAttribute() {
        return $this->connectionsTo->merge($this->connectionsFrom);
}

the merge method should be called on collection

5th October, 2018

s4muel left a reply on Token Mismatch Exception • 2 weeks ago

weird, the documentation says:

The CSRF middleware is automatically disabled when running tests.

if you are on a 5.2 version (which i hope, you;'re not) i would suggest: https://laravel.com/docs/5.2/testing#disabling-middleware

s4muel left a reply on Developing Relationship Between Users As "Connections" • 2 weeks ago

not sure you can do it in a simple way, i think you need to combine them manually, so create two relations:

public function connectionsTo()  
{  
    return $this->belongsToMany(User::class, 'connections', 'user_id', 'connection_id')->whereNotNull('accepted_on');  
}

public function connectionsFrom()  
{  
    return $this->belongsToMany(User::class, 'connections', 'connection_id', 'user_id')->whereNotNull('accepted_on'); //mind the reversed 'key' parameters
}

public function getConnectionsAttribute()
{
    return $this->connectionsTo()->merge($this->connectionsFrom());
}
// and then access it on user object as such:
$user->connections; //that is a collection

not tested, but it hope something like that should work

20th September, 2018

s4muel left a reply on Laravel-5.2 Css And Js Not Working Without Asset • 1 month ago

<link href="css/app.css" rel="stylesheet">

s4muel left a reply on How To Fix Error In User Verification Plugin On New User Creation? • 1 month ago

according to this method: https://github.com/jrean/laravel-user-verification/blob/7.0/src/UserVerification.php#L367

the user table should have these columns:

  • verified
  • verification_token

does it?

s4muel left a reply on How To Handle A 3 Way Join On A Join Table, Not The Entities Themselves • 1 month ago

i would store that user and whisky information in the Review table review

  • id
  • user_id
  • whisky_id
  • ...

s4muel left a reply on WEEKDAY() Wont Work Non Sqlite Database • 1 month ago

not sure about it, but give it a try``` $weekday_today = date('N');

//if you want to support multiple databases, switch the code, depending on DB::getDriverName() //...

$weeks = Book::whereRaw("CAST (strftime('%w', date) AS Integer) = " . date('N'))->get();

s4muel left a reply on Help With Guzzle Put And Post • 1 month ago

you are not sending the evento id

19th September, 2018

s4muel left a reply on Validation Error • 1 month ago

18th September, 2018

s4muel left a reply on Help With Guzzle Put And Post • 1 month ago

Please, use markdown in your messages. This is so unreadable.

Hard to tell without seeing the webapi endpoint. I still think it is a problem on the endpoint. There is an error 500, right? Enable debugging, check the logs. Try to use Postman and send the request "by hand", or use cURL, does it work?

Rest APIs requests usually (not necessarily) have an identifier that defines which record do you want to edit by a POST or PUT. Aren't you missing something?

s4muel left a reply on Subdomain As Api • 1 month ago

you mention http://api.domain.com/v1, but the route definition defines this: http://api.domain.com/api/v1/ either change your prefix, or a hit this url

s4muel left a reply on Help With Guzzle Put And Post • 1 month ago

seems like a problem on C# WebAPI side. see the logs in the WebAPI, anything suspicious? does it properly consume application/x-www-form-urlencoded?

s4muel left a reply on Cant Start Httpd • 1 month ago

something is running on port 80 already, check what it is running netstat netstat -tulpn | grep :80

s4muel left a reply on Pivot Table Factory Seeding • 1 month ago

if you have a dedicated model for assigned_users (e.g. UserPost), use this approach:

$factory->define(App\UserPost::class, function (Faker $faker) {  
    return [  
        'user_id' => factory(App\User::class)->create()->id,  
        'post_id' => factory(App\Post::class)->create()->id,
    ];
});  

if you don't, use a DB table insert:

DB::table('assigned_users')->insert(
    [
        'user_id' => factory(App\User::class)->create()->id,  
        'post_id' => factory(App\Post::class)->create()->id,
    ]
);

and finally, if you want to use existing users/posts, use a callback

DB::table('assigned_users')->insert(
    [
        'user_id' => function () {  
            return App\User::all()->random()->id;  
        },
        'post_id' => function () {  
            return App\Post::all()->random()->id;  
        },
    ]
);

that should yield some multiple assigned users by chance, or better yet amend the callback as you wish to randomize only couple of them

s4muel left a reply on Laravel 5.7 Upgrade Issues • 1 month ago

how exactly did you upgrade, did the composer update ran successfully? looks like you're still using the 5.6 version of [DIRECTORY]/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php https://github.com/laravel/framework/blob/5.6/src/Illuminate/Auth/SessionGuard.php#L583 3 arguments are passed inside version 5.7's fireAttemptEvent(...) method: https://github.com/laravel/framework/blob/5.7/src/Illuminate/Auth/SessionGuard.php#L584

s4muel left a reply on Rules - Need To Check If There Are Existing Values • 1 month ago

read here about ignoring the currenlty edited entry when checking unique rule https://laravel.com/docs/5.7/validation#rule-unique (part "Forcing A Unique Rule To Ignore A Given ID")

s4muel left a reply on Laravel Select • 1 month ago

return view('/website/index', compact('data', 'mdata', 'sdata');

17th September, 2018

s4muel left a reply on MY DISTINCT KEYWORD NOT WORKING • 1 month ago

$coachingCity = Coaching::distinct()->orderBy('C_city')->get(['C_city'])

12th September, 2018

s4muel left a reply on Model Update Error • 1 month ago

the second error message is strange as well, the The :attribute format is invalid string is present only for these rules: regex, not_regex, url

https://github.com/laravel/laravel/blob/master/resources/lang/en/validation.php

s4muel left a reply on Model Update Error • 1 month ago

strange indeed, i wonder why the error message says it should be at least 2 characters, when there is min:10 in the rule.

@manogi ?

14th August, 2018

s4muel left a reply on Laravel - Make A Filter With Relations • 2 months ago

try that on smaller dataset and inspect the SQL in say laravel debugbar if the query is correct.

13th August, 2018

s4muel left a reply on Help • 2 months ago

$project = Project::find($id)  
 ->join('credentials', 'credentials.project_id', '=', 'projects.id')  
 ->join('tasks', 'tasks.project_id', '=', 'projects.id')  
 ->join('wiki', 'wiki.project_id', '=', 'projects.id')  
 ->select(  'projects.name',  
  'projects.created_at',  
  'credentials.user_id',  
  'credentials.created_at',  
  'tasks.tag_name',  
  'tasks.created_at',  
  'wiki.data'  
  )  
 ->where('projects.id', '=', $id)  
 ->orderBy('tasks.created_at', 'desc')  
 ->orderBy('credentials.created_at', 'desc')  
 ->orderBy('wiki.created_at', 'desc')  
 ->limit(20)  
 ->get();

nice title though;)

s4muel left a reply on Laravel - Make A Filter With Relations • 2 months ago

you mean something like this?

$products = $category->products()->whereHas('specvalued', function ($query) {
    $query->where('value', 2017);
})->orderBy('position')->paginate(20);

s4muel left a reply on Should I Be Using Models In Lumen? • 2 months ago

well, lumen is the "speedy brother". it has just been disabled to make it a bit more more swift. but if you need it, just enable it and use it as you like;)

9th August, 2018

s4muel left a reply on Laravel Backpack File Upload • 2 months ago

just shooting from the hip, have you tried setThumbnailImageAttribute($value) instead of setthumbnail_imageAttribute($value)?

s4muel left a reply on Laravel Can't Find Other Lang Files ? • 2 months ago

aren't you missing one directory level (resources/lang/en/auth.php)? https://laravel.com/docs/5.6/localization#introduction

s4muel left a reply on Laravel Can't Find Other Language Files • 2 months ago

aren't you missing one directory level (resources/lang/en/auth.php)? https://laravel.com/docs/5.6/localization#introduction

s4muel left a reply on Laravel Backpack File Upload • 2 months ago

i havent't seen backpack before, but this pops-out for me in here:

public function setImageAttribute($value)  
{  
  $attribute_name = "image";  
  $disk = "public";  
  $destination_path = "/uploads";  
  $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);  
}

You use setImageAttribute and set the name to image $attribute_name = "image";, shouldn't it be thumbnail_image?

13th March, 2018

5th March, 2018

s4muel left a reply on Storage (storage/app) Folder Permissions? • 7 months ago

from the laravel documentation

Directory Permissions

After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run.

this should be fine: change the owner (+group) of the folder to www-data, then use 755 permissions on the folder itself, 644 on the files

4th March, 2018

s4muel left a reply on How To Make A Dropdown List Suggest Only Options In Relation With A Selected Value? • 7 months ago

  • you have a route for ajax-metier Route::get('/ajax-metier',function(){...}) but in the create.blade.php file you do request the ajax-tac route: $.get('/ajax-tac?met_id=' \+ met_id, function(data){...})
  • and your html select element id is Tache <select name="tache" id="Tache" class="form-control"> but you use tache in the javascript $('#tache')

could that be a problem?

i used this JS library some time ago https://github.com/tuupola/jquery_chained, might help you clean things up a bit. have a look.

and you probably have a typo here: console.long(e);

12th January, 2018

s4muel left a reply on Question Regarding Collection Sorting And Case Sensitivity • 9 months ago

$collection = collect(['test', 'Test', '1', 'Alphabet', 'bob'])->sortBy(function ($value) {
    return $value;
}, SORT_NATURAL | SORT_FLAG_CASE);

s4muel left a reply on Cur Call • 9 months ago

the easiest way (workaround) is to set the curl options to disable the cert verification

$curl_handle = curl_init("https://host/path");
curl_setopt($curl_handle , CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle , CURLOPT_SSL_VERIFYHOST, false);

note: if this workaround is a real security issue for you, you should create trusted certificate, or at add the CA to your trusted ones. google for CURLOPT_CAINFO, set the PEM file (use this one or another trusted one) and append the server's PEM certificate in it)

11th January, 2018

s4muel left a reply on .htaccess Redirection • 9 months ago

just a note: malformed .htaccess might definitely result in error 500.

but even if i don't like the first RewriteRule without the Substitution part (second 'parameter' ), this doesn't look like that case;)

s4muel left a reply on Count Distinct From Pivot Table, But Change The ID Column To The "name" Column? • 9 months ago

i don't know if there is more "Eloquent" solution (i hope so;), but this should work too:

Route::name('count')->middleware(['auth'])->get('sammanstall', function(){
    $inventory = DB::table('inventories')
        //i suppose your Materials Table is 'materiels' and the column with Material Name is 'materiel', update as needed
        ->select('materiels.materiel', DB::raw('count(*) as total'))
        ->groupBy('materiel_id')
        ->join('materiels', 'inventories.materiel_id', '=', 'materiels.id')
    return $inventory;
});

s4muel left a reply on Markdown Editor With Toolbar • 9 months ago

I was about to start a new thread about this feature, glad i am not alone in this MD darkness. At least a preview would be totally ninja. @JeffreyWay, any chance?

s4muel left a reply on Multipart Guzzle Request With Laravel • 9 months ago

are you sure about this part?

...
'contents' => file_put_contents($tmp, file_get_contents($imagePath)),
...

because the file_put_contents does return just number of written bytes (or false) see the file_put_contents documentation

just shooting from the hip, but try this instead:

...
'contents' => file_get_contents($imagePath),
...

14th October, 2017

s4muel left a reply on Running Php Artisan Error • 1 year ago

add that, try it and let me know if it helped

30th September, 2017

s4muel left a reply on Correct Eloquent Relationships For A "Favorite", "Like", Or "Star" Feature • 1 year ago

you are right, just create also anuser_id column in favorites table and create Eloquent relations as needed (you probably wont always need to set the model relationship in both ways)

check out Favorite, Reply, User models and Favoritable trait https://github.com/laracasts/Lets-Build-a-Forum-in-Laravel/tree/master/app (and the related videos if you can). the models there grew a bit bulky and advanced, but i think you will get to the point.

s4muel left a reply on To Write To Log File Transaction Commands • 1 year ago

you will probably need a new listener for that, add this to your app/Providers/EventServiceProvider.php file to the boot() method

public function boot()
{
    parent::boot();
    //...
    Event::listen(
        [TransactionBeginning::class, TransactionCommitted::class, TransactionRolledBack::class],
        function ($event) {
            dump($event);//
        });
    }
}

all of these three events extend the ConnectionEvent event and contain these attributes: $connectionName and $connection

Edit Your Profile
Update

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