Cronix

Experience

118,990

114 Best Reply Awards

  • Member Since 3 Years Ago
  • 482 Lessons Completed
  • 1 Favorite

26th July, 2017

Cronix left a reply on Laravel Input Form Arrays: Check Atleast One Entry Is Added • 3 hours ago

Why the need for complex arrays? They don't seem necessary or fully used. What's wrong with just levels[] and build_time[]

In your controller, you could just check

// level array or build_time array don't have a value, send error
if ( ! count($request->levels) OR ! count($request->build_time)) {
    return response('Please complete at least one entry.', 422);
}

// there's at least one entry, validate and save.

25th July, 2017

Cronix left a reply on Your File Must Be Of Kind: Jpeg, Jpg, ... • 21 hours ago

do you have more than one file input? Just curious because the name of your input is using array syntax with the [].

Cronix left a reply on When Allowing A User To Editing Some Random Text, What Is The Best Way To Pass The Id Of Said Text? • 23 hours ago

No problem. Please mark whatever answer helped as the solution by clicking the circled checkmark under the username of the post that helped.

Cronix left a reply on When Allowing A User To Editing Some Random Text, What Is The Best Way To Pass The Id Of Said Text? • 23 hours ago

if($request->user()->username == Auth::user()->username) {

Those 2 things are identical, so it would always be true.

Cronix left a reply on When Allowing A User To Editing Some Random Text, What Is The Best Way To Pass The Id Of Said Text? • 23 hours ago

I see. Then it's fine to be a regular link, but I wouldn't show that edit link unless the "text" was created by the currently logged in users id.

Like the db table where you are storing these "texts" should have minimally these 3 fields:

-id (id of text)
-user_id (id of text author)
-text (the actual "text")

So when displaying the links, something like:

// Only display edit link if logged in user is author of "text"
@if ($text->user_id === Auth::id())
    <a href="http://url.com/edit/12345">Edit</a>
@endif

Cronix left a reply on When Allowing A User To Editing Some Random Text, What Is The Best Way To Pass The Id Of Said Text? • 23 hours ago

That's hard to answer with the info provided. For instance, it doesn't matter if you're using js/ajax. If it's a regular, traditional form with no js/ajax, it should be a regular submit button.

Cronix left a reply on When Allowing A User To Editing Some Random Text, What Is The Best Way To Pass The Id Of Said Text? • 23 hours ago

That's not exactly what you're doing. You're just accepting the input regardless as long as it's an integer, etc.

Ex:

if ($request->id === Auth::id()) {
    // this is the author. Validate and save.
} else {
    // this is NOT the author, reject with error message.
}

Cronix left a reply on When Allowing A User To Editing Some Random Text, What Is The Best Way To Pass The Id Of Said Text? • 1 day ago

I'd be storing the id of the person who created the "text", and then when editing, check that the logged in user who is trying to edit matches the id of the person who created the text. If they match, then save the edit, if not, reject it.

Cronix left a reply on When Allowing A User To Editing Some Random Text, What Is The Best Way To Pass The Id Of Said Text? • 1 day ago

How are you allowing them to edit said text? A form? You could just use a hidden form field with the id.

Cronix left a reply on Laravel Not Load My Edited Js File • 1 day ago

are you versioning your files with mix?

Cronix left a reply on How Do I Prevent The Mismatch Token Error In Laravel? • 1 day ago

That solution probably won't work as-is with ajax calls since it's redirecting and not returning json.

Cronix left a reply on JQuery AJAX Request That Returns Html And Php Variable (Laravel) • 1 day ago

in the success event of the first ajax call, just grab the values you need from the form inputs on the first form and assign them to the inputs on your 2nd form.

$('#fieldFrom2ndForm').val($('fieldFromFirstForm').val());

Cronix left a reply on How Do I Prevent The Mismatch Token Error In Laravel? • 1 day ago

Another solution is this simple package: https://github.com/GeneaLabs/laravel-caffeine

It just sends an ajax request every x minutes to keep the session alive on pages that have a _token field (or you could use a meta field). You could set it for once/hour or something since your sessions are 2 hours long so they won't time out.

Cronix left a reply on How To Pass Checkbox Value 0 If Not Checked And 1 If Checked. • 1 day ago

$checked = $request->has('delete') ? 1 : 0;

Just check whether it passed anything for that field. If it did, it was checked and assign the value of 1, if it didn't it wasn't and assign value of 0. It doesn't matter if you use 1/0 or on/off for your values. If the field exists in the request it means it was checked because html doesn't send unchecked values.

Cronix left a reply on Mix: How To Clean Public/css And /public/js Folder When Using Version() ? • 1 day ago

Yes, update to newest mix. It uses query strings for cache busting instead of hashes in the filenames, so it won't be creating additional files.

24th July, 2017

Cronix left a reply on Laravel 5.4 And Form Arrays • 1 day ago

This might work

$dataSet = [];
foreach($request->airline as $index => $airline) {

    $dataSet[] = [
        'airline' => $airline,
        'flightNumber' => $request->flightNumber[$index],
        'departing' => date('Y-m-d H:i:s', strtotime($request->departing[$index])),
        'seatNumber' => $request->seatNumber[$index],
        'tripID' => $request->tripID,
        'userID' => Auth::id(),
    ];
}

DB::table('flights')->insert($dataSet);

Cronix left a reply on Browser Back Button Counts As Ajax Request? • 1 day ago

Are you sure it's not just showing you the cached version (browser cache) of the last page? I doubt it's actually firing off an ajax request, unless you are firing an ajax request on page load or something like that. What do your dev tools in the browser show? Is there an ajax request being made?

Cronix left a reply on Access A JQuery Variable Within A Vue.js Component • 1 day ago

I think you can read it with jquery in the mounted() hook, and then set it in data.

Cronix left a reply on Count Records From Current Month • 1 day ago

you're only checking for things on the first day of the month. Need to use between first day and last day of month to get everything for the month.

$today = Carbon\Carbon::today();
->whereBetween('date', [$today->startOfMonth(), $today->endOfMonth])->count();

Cronix left a reply on How To Forbid Multiple Responses • 1 day ago

You need to store which user answered each question (presumably in your feedbackpost db table), and then before saving, check to see if the user already answered the question(s) by checking if their id/question combo already exists in the db.

Cronix left a reply on MySQL Connections Over SSL • 2 days ago

Have you tried setting the cipher? PDO::MYSQL_ATTR_SSL_CIPHER

Cronix left a reply on Spark: Profile Image Not Found. • 2 days ago

@Korona123 You need to register your github with Spark via the spark website when logged in in order to access the private spark repo.

Cronix left a reply on MySQL Connections Over SSL • 2 days ago

what does your mysql config look like? Are you using "options"?

23rd July, 2017

Cronix left a reply on Retrieving From DB • 3 days ago

In the controller, do a dd($Delivery) before you return the view. Does it get the $Delivery properly?

Cronix left a reply on Getting A Single Item From List Of Data • 3 days ago

Use first(), not find().

find() also takes the id, (->find($id)) so you don't have to do where('id', $id)

Cronix left a reply on Retrieving From DB • 3 days ago

try artisan view:clear to remove the cached view

Cronix left a reply on Retrieving From DB • 3 days ago

You're overwriting $Delivery in that foreach(). Don't do "foreach(x as x)" do foreach (x as y).

@foreach ($Delivery as $item) { echo $item->Address; } @endforeach }

Cronix left a reply on Retrieving From DB • 3 days ago

what does your view look like?

Cronix left a reply on Retrieving From DB • 3 days ago

The error message is pretty self-explanitory. In your 'Delivered' view, you're not passing a variable from the controller to the view called 'Delivery', but are trying to use it.

22nd July, 2017

Cronix left a reply on Generate Route From A Boostrap Modal • 4 days ago

See how they do it on the example page: http://getbootstrap.com/javascript/#modals-related-target

so you could store your "product-name" for each button that launches your modal. When the modal is opened you could grab that "product-name" and make a link from it, like href="http://yourdomain.com/brand/category/" + button.data('product-url')

20th July, 2017

Cronix left a reply on Homestead Mysql Access From Host • 5 days ago

I'm connecting with Sequel Pro on my host, using default homestead settings:

host: 127.0.0.1 Port: 33060 User: homestead Database: homestead Pass: secret

Did you try 127.0.0.1 instead of the homestead box's IP?

Cronix left a reply on Homestead Mysql Access From Host • 5 days ago

127.0.0.1:33060 from host works for me.

Cronix left a reply on How To Read CSV Into Array From Storage Directory? • 5 days ago

I think you'd just do an array_shift($file).

Cronix left a reply on How To Read CSV Into Array From Storage Directory? • 5 days ago

What do you mean by "headers"?

Cronix left a reply on How To Read CSV Into Array From Storage Directory? • 5 days ago

$file = Storage::get('a.csv');

Cronix left a reply on Get Array Value From An Array • 5 days ago

I assume you're only going to get a single result from the query, so use ->first() instead of ->get() so it will return the single entry instead of an array of entries.

$download = DB::table('a') ->select('a.file_name') ->where('a.id',"abc.csv") ->first();

echo $download->file_name;

Cronix left a reply on Mass Assignment Using UpdateOrCreate Method • 5 days ago

If it works, please mark the correct answer as solved.

Cronix left a reply on Help, Can't Install Laravel Mix In Laravel Homestead. • 5 days ago

It's because the windows filesystem and linux filesystems are completely different (permissions, symlinks, etc).

Cronix left a reply on Help, Can't Install Laravel Mix In Laravel Homestead. • 6 days ago

yes, run all npm commands from the vm, not your host.

Cronix left a reply on How To Know If A SQL Request Return Something • 6 days ago

A few things you could do.

// check if the collection is empty
if (dimLHD->isEmpty()) {
    // Didn't find the record
}

You could also use firstOrFail() for your query instead of get(), which will throw a 404 error if not found. https://laravel.com/docs/5.4/eloquent#retrieving-single-models

Cronix left a reply on Mass Assignment Using UpdateOrCreate Method • 6 days ago

Room::updateOrCreate(
[
    // this first array is used to check if these fields/values exist in the db
    // if that record exists, it will update with the 2nd array below
    // if it doesn't exist, it will create new record with 2nd array below
    'type' => $data['type'][$i]
],
[
    // actual data to either insert or update
    'house_id' => $hostel->id,
    'user_id' => Auth::id(),
    'type' => $data['type'][$i],
    'price' => $data['price'][$i],
    'space' => $data['space'][$i]
]);

19th July, 2017

Cronix left a reply on Mass Assignment Using UpdateOrCreate Method • 6 days ago

updateOrCreate takes 2 array parameters. First array is what to look for to determine if the record exists, 2nd array is data to update or insert.

Most likely your first array would be ['house_id' => $hostel->id, 'user_id' => Auth::id()] (or maybe just house_id) and the 2nd array is what you already have.

So it would look for house_id = $hostel->id AND user_id = Auth::id(). If that exists, it will update that record using values from 2nd array. If not, it will create using values from 2nd array.

Cronix left a reply on How Do I Publish My Public Assets In A Clever Way With Laravel And Laravel Mix? • 6 days ago

I commit both the compiled minified and regular versions to git. In the master template it checks to see if it's production, and loads minified versions, otherwise it uses regular versions.

@if (App::environment('production'))
    <script src="{{ mix('/js/file.min.js') }}"></script>
@else
    <script src="{{ mix('/js/file.js') }}"></script>
@endif

I version them with mix, so you need to include the /public/mix-manifest.json file in your repo as well and then just use <script src="{{ mix('/js/file.js') }}"></script> and in the browser it outputs the versioned file with the cache-busting querystring (/js/file.js?laksjwerlkjasaslkjf)

There are a lot of ways to do this, but that's what I usually do.

Cronix left a reply on Bootstrap Markdown • 6 days ago

Never use that package, but I assume there's some sort of css that you need to include on the frontend?

Cronix left a reply on Error While Updated To Last PHPStorm Version • 1 week ago

As I mentioned in the other thread, check if the user is authenticated first before trying to access user properties. You should really keep the same question to a single thread instead of multiple.

if (Auth::check()) {
    // user is signed in, so properties exist
}

Cronix left a reply on Error If The User Is Not Logged In. • 1 week ago

check if they are signed in yet before trying to access user properties.

if (Auth::check()) {
  // Auth::user()->username exists.
}

Cronix left a reply on Change Pricing Of Spark Plan, Keep Users On Hold Plan • 1 week ago

I haven't tried that, but I believe it works the way you described. The only caveat I can think of is in your subscriptions/team_subscriptions tables, it will have the same "name" as your other plans ("Standard"), but use the new stripe_id ("standard-monthly").

Cronix left a reply on Error While Updated To Last PHPStorm Version • 1 week ago

try artisan view:clear

Don't mess with the temporary cached files in /storage/framework/views... They will get overwritten anyway because those are your compiled blade templates.

Edit Your Profile
Update

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