Cronix

Experience

649,570

859 Best Reply Awards

  • Member Since 4 Years Ago
  • 757 Lessons Completed
  • 3 Favorites

19th August, 2018

Cronix left a reply on How To Dispaly School_id Related To Itself • 10 hours ago

I'm sorry I can't help here.

Cronix left a reply on When Mass Assignment Is Happening? • 10 hours ago

Ah, well I'd advise not to use enums anyway. They're problematic in a lot of ways, and should really use a lookup table instead.

Cronix left a reply on How To Dispaly School_id Related To Itself • 10 hours ago

Man, you have a bunch of confusing code, and I'm still not clear on what you're actually trying to do lol.

$("#activity-forms").submit(function (event) {
        event.preventDefault();
        cluster_id = $('#cluster_id').val();
        group_id = $('#group_id').val();
        console.warn(_school_id);
        $.post("{{ route('activity.store') }}", {_school_id:_school_id, cluster_id:cluster_id, group_id:group_id}, function (data_activity) {
            console.log(data_activity);
            load_activity();
        });
    });

In there, in the ajax request where you call load_activity(), is that supposed to get the activities for whatever school you just created an activity for?

Cronix left a reply on You Need To Set Up The Project Dependencies Using Composer • 10 hours ago

Are you on a vm or something? If so, are you ssh'd into the vm when running the tests?

Cronix left a reply on How To Dispaly School_id Related To Itself • 10 hours ago

I can't see anywhere in that code that read_activity() is actually called. I see it defined. I see a route to it. Neither one of your ajax calls are hitting that route. So, where is it being called from?

Cronix left a reply on When Mass Assignment Is Happening? • 11 hours ago

You should have gotten the same error, unless you passed something in your test that you didn't originally pass in your controller, so it didn't trigger the error bc everything in that request was in the $fillable array. Anytime the create() method is used it checks for mass assignment.

Cronix left a reply on Html Collective Select - Unsupported Operand Types • 11 hours ago

sorry, I was editing my answer

Cronix left a reply on Html Collective Select - Unsupported Operand Types • 11 hours ago

use toArray() so it's a php array instead of an eloquent collection.

{!! Form::select('parent_id', [''=>'Glavna kategorija']+$categories->toArray(),null,['class'=>'form-control']) !!}

Cronix left a reply on Cannot Access New Folder Under Public • 12 hours ago

Hmm, well you're doing this on the windows (host) side. Try creating the symlinks when you're ssh'd into the vm.

Cronix left a reply on Cannot Access New Folder Under Public • 12 hours ago

Do you have a /avatars route too or something?

Cronix left a reply on Cannot Access New Folder Under Public • 12 hours ago

I'm not sure on windows (haven't used it in years). I'd try using full paths.

Cronix left a reply on Cannot Access New Folder Under Public • 13 hours ago

I'd look at the owner and permissions of that dir and see if they're readable/writable by the web user.

Cronix left a reply on Mass Updating The Order Of Models With Eloquent • 13 hours ago

@stanjg You're welcome! Please mark as solved if your question is adequately answered.

Cronix left a reply on Video Tag In Vuejs Give Error • 14 hours ago

if test.mp4 is in /public/images/videos/test.mp4, the url would just be /images/videos/test.mp4

Cronix left a reply on Call Class On __construct Controller • 14 hours ago

protected function machenAddSaldo(Request $request){

         if($saldo_service->tambahSaldoKonsumen($request)){
                return response()->json([
                  'response' => 'success',
                ]);
           } else {
                return response()->json([
                  'response' => 'failed',
                ]);
            }
    }

$saldo_service is a class property, and not a local variable defined in machenAddSaldo. Use $this->saldo_service instead.

Cronix left a reply on Mass Updating The Order Of Models With Eloquent • 14 hours ago

It would be really messy. Really, this isn't that big of a deal unless you are a very populate site. Eloquent doesn't have a way to do multiple updates in a single query like you're needing. You'd have to do it manually, something like: https://stackoverflow.com/questions/3432/multiple-updates-in-mysql

Cronix left a reply on Mass Updating The Order Of Models With Eloquent • 14 hours ago

why can't you do it in the query itself?

$posts = $request->input('posts');

foreach ($posts as $post) {
    $p->where('id', $post->id)
        ->where('user_id', '!=', auth()->id())
        ->update(['order' => $post->order]);
}

Cronix left a reply on Mass Updating The Order Of Models With Eloquent • 14 hours ago

if ($p->user_id !== auth()->id())
        continue;

I'd try to do that check on the javascript end and only send through the id's of ones that should be reordered. That would save you a query in each loop (you're performing 2) as you could just update instead of retrieve and then update.

Cronix left a reply on Can't Make Phpunit Configurations To Work With DatabaseMigrations Trait • 15 hours ago

make sure your config isn't cached. php artisan config:clear

Cronix left a reply on How To Dispaly School_id Related To Itself • 15 hours ago

@RonB1985 remove $school_id from single quotes in last code

Cronix left a reply on Controller Is Redirecting Me To A Post Route And Not The One I Wrote • 15 hours ago

@Bole_nbg You have a lot of duplicated code, as well. You could simplify it a lot.

protected function saveToDrafts($request, $email_id){
   
    if($email_id){
        //znači dolazimo sa edit. ne pravimo novu instancu nego koristimo postojeći red
        $email=Email::findOrFail($email_id);   
        $request->session()->forget('email_id');
    }else{
        //znači ne dolazimo sa edit stranice. pravimo novu instancu tj novi red i dajemo is_draft=true
        $email=new Email();
        $email->is_draft=true;        
    }

    // these are being set/saved for both, so they don't need to be in both if/else
    $email->sender=Auth::id();
    $email->receiver=$request->receiver;
    $email->title=$request->title;
    $email->body=$request->body;
    $email->save(); 

    Log::info('hey'); // THIS WORKS
    toastr()->success('Email saved to drafts successfully!');

}

Cronix left a reply on Will A Laravel Spark 6 License Allow Install Of Spark 5.0? • 15 hours ago

Whatever version you get, you get access to all past versions. Spark 6 does have a different git repo than 1-5 though, but you'll get access to both.

Cronix left a reply on No Message On AJAX POST Request • 15 hours ago

@Aaranihlus If your js is in a separate js file (not in the view), it could have been a browser caching issue. Forcing the browser to reload the page or clearing cache usually helps. When working with javascript, I usually turn caching off in the browser for that site via the dev tools (most have a checkbox for this option)

Cronix left a reply on How To Dispaly School_id Related To Itself • 16 hours ago

You're not providing enough info, or asking a complete question that can be easily answered.

I want to dispaly school_id related to itself

What does that mean? Related to itself how? In what way? Is it a specific school? If so, how do you know the ID of the school you're trying to view? You need to actually explain what you're wanting instead of showing us code that doesn't really make sense.

If you're wanting to get activities for a specific school, you need to somehow pass the id of that school to your method and use that in the query.

Cronix left a reply on No Message On AJAX POST Request • 16 hours ago

In the browsers dev tools, is the ajax request going to the correct url?

Cronix left a reply on How To Integrate Third Party APIs In A Clean Way • 16 hours ago

You probably won't be able to run redis on shared hosting. Just create a migration to make a table to hold the data, and a model. Just retrieve, and store in the db like you would normally.

Do you think 15 minute old exchange rates will really matter much? 5 minutes old? You can hit it as much as the api allows.

Cronix left a reply on Laravel Blade Multidimensional Array • 16 hours ago

@evripidesk

@foreach ($daysArray as $day)
    <td >{{  $day }}</td>
@endforeach 

will break your table though. The first exercise has 2 days listed, so this is making 2 <td>s (4 columns total for first row). Then the 2nd exercise has 1 day, so that row only takes up 3 columns. So, you end up with invalid html.

It would probably be best to comma separate the days.

<td>{{ implode(', ', $daysArray) }}</td>

Then each row will only have 3 columns (not breaking the table), with the days column being comma separated days.

18th August, 2018

Cronix left a reply on How To Integrate Third Party APIs In A Clean Way • 1 day ago

Usually when working with apis like that, I like to write a scheduled job to fetch the data at regular intervals (whatever the api allows, or however current I need it to be). Then when I need the data I just query the local db (or redis cache). That allows faster response times to your end user. It's always slower hitting an api, and you're hitting 3 separate ones. Also, what if one of the apis goes down, or becomes really slow? You can alert yourself with a failed job notice, but your app will still work ok because you're pulling whatever the latest data was from your local db and not relying on the api to deliver it to you in realtime. Of course the use case varies, but that's generally how I like to do stuff like that.

Cronix left a reply on How To Get The Info From The Array To Store In The Answers Table? • 1 day ago

Yes, the way you're sending the data from your form is very problematic, as you can probably see from your last few threads on basically this same thing.

Cronix left a reply on Is There A Way To Randomize Css Classes In Laravel • 1 day ago

I can't think of a easy/really good way to do that. You'd probably end up using regex to search/replace classnames using regex or str_replace(), but you'd have to do it on every request. You'd have to have some sort of css controller that would load the css file, manipulate it, and send it to the browser instead of the browser directly downloading the css file, as well as an after-middleware to replace the same placeholders in the views that are being sent to the browser for the class names. There would be a performance penalty too. Not really sure, just thinking out loud here. You'd lose the ability for the browser to cache pages, as well, since the same url could provide different output for each hit.

Cronix left a reply on Is There A Way To Randomize Css Classes In Laravel • 1 day ago

This sort of thing is easiest to do on the main <body> tag. It's not laravel specifc, but doesn't need to be.

@php($themes = ['one', 'two'];

<body class="{{ $themes[array_rand($themes)] }}">
    <div class="something">wow, a div</div>
</body>

Then have css rules like

.one div.something { color: blue }
.two div.something { color: green }

Cronix left a reply on MethodnotAllowed Exception After Login • 1 day ago

Next, you should modify the RedirectIfAuthenticated middleware's handle method to use your new URI when redirecting the user.

https://laravel.com/docs/5.6/authentication#included-authenticating

Did you do that as well?

Cronix left a reply on MethodnotAllowed Exception After Login • 1 day ago

should redirect to the "/" route like I defined it in the LoginController

How are you doing that?

Cronix left a reply on Laravel Blade Multidimensional Array • 1 day ago

No, I don't. They're all a bit different, so the answers are as well.

Cronix left a reply on Overriding /storage/ URL • 1 day ago

My advice is to prevent them from being able to view the image directly via example.com/storage/images/1.jpg, which is called "hot linking". This will check the request referrer, and if it isn't from your website, it won't allow it. So if they view it through a webpage on your site, it will allow it. If they try to view it directly via the url, it won't.

How you do it depends on the webserver you're using (nginx/apache, etc). Just google "apache prevent hotlinking" or whatever

Here's an example for apache

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]
RewriteRule \.(gif|jp?g|png)$ - [F]

So it would apply to .gif, .jpg, .jpeg and .png files for example.com.

Cronix left a reply on Laravel Blade Multidimensional Array • 1 day ago

<tbody>
    @foreach ($chests['chest'] as $exerciseName => $daysArray)
        <tr>
            <td>{{ $exerciseName }}</td>
            <td>{{ array_sum($daysArray) }}</td>
            <td>{{ $chests['hints'][$exerciseName][0] }}</td>
        </tr>
    @endforeach
</tbody>

produces

Chest Press | 1 | test1
Flys        | 7 | test 2

is that correct?

Cronix left a reply on Laravel Blade Multidimensional Array • 1 day ago

How is this supposed to look, with your given data?


Exer | Days | Hints
-----+------+------

fill it in...

Cronix left a reply on Share The Code Between Store And Update • 1 day ago

Sure, they're just variables. You could simplify it a bit more. You'll notice you're returning the same redirect in both places, too.

public function store(BookRequest $request)
{
    $this->saveBook($request, (new Book));
}

public function update(BookRequest $request, Book $book)
{
    $book = $this->saveBook($request, $book);
}

private function saveBook($request, $model)
{
    $model->title = $request->input('title');
    $model->author = $request->input('author');
    $model->save();
    return redirect()->route('book.show', $model);
}

Cronix left a reply on Share The Code Between Store And Update • 1 day ago

Looks ok, is it working?

Cronix left a reply on Read The Content Of The Local Downloads Directory • 1 day ago

This is most likely a file permission issue. The user your webserver runs under needs to have read access to whatever dir you're reading from.

Cronix left a reply on Mailable: Non Numeric Value Encountered • 1 day ago

@vincej You're welcome. Please mark the thread as solved.

Cronix left a reply on Get Path By Route Name • 1 day ago

I find it ugly to have links on my site with whole url insteand just path to resource.

That's kinda funny lol

Cronix left a reply on Get Path By Route Name • 1 day ago

Can you explain a bit about why, and where you'd need to do this? There are ways to get that but it depends... so need a bit more info. Do you need to get it from a request object, or ?

Cronix left a reply on Mailable: Non Numeric Value Encountered • 1 day ago

so ['url' => 'http://192.168.1.92/view_customer_quote/' . $quote]) doesn't work?

btw, you should use the url() helper and not hardcode your url. That will make upgrading a pain in the ass since you'll have to manually update every place you hardcoded the urls...

url('view_customer_quote/' . $quote)

it will use whatever host url you have set for APP_URL in your .env file, so all you have to do is change that one variable when you change hosts (or put this on a live server).

Cronix left a reply on Mailable: Non Numeric Value Encountered • 1 day ago

public $quotation;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($quotation)
    {
        $this->quote = $quotation;
    }

because you create a public $quotation variable, but in the constructor you set $this->quote... so it didn't get assigned.

change public $quotation to public $quote, and in the view, reference {{ $quote }} for the output.

Cronix left a reply on Mailable: Non Numeric Value Encountered • 1 day ago

Mail::to($customer['email1'])->send(new SendCustomerQuote(DON'T KNOW WHAT TO PUT IN HERE));

you put the quote id there, since that's the thing you're trying to send as a variable in the email view, right?

show your

public function save_quote(Request $request)

method, not just the line where you're sending the email. I'm sure that's where this mysterious $ref_id is coming from that needs to be passed to the mailable.

Cronix left a reply on Mailable: Non Numeric Value Encountered • 1 day ago

Yes, as I said you need to send the quote to the SendCustomerQuote() class, like I showed.

Cronix left a reply on Mailable: Non Numeric Value Encountered • 1 day ago

whichever one had the above line in it. I'm getting lost in the things that have been altered so far...

Cronix left a reply on Mailable: Non Numeric Value Encountered • 1 day ago

Like you were before, Mail::to($customer['email1'])->send(new SendCustomerQuote($newQuotation)); You have to send the quotation to the mailable.

For now, try changing your constructor to

public function __construct($quotation) // remove QuotationController 
{
    $this->quote = $quotation;
}

Cronix left a reply on Send Data From Blade Form View To External POST • 1 day ago

I think my problem is something with routing as I cannot pass the form field data to the First Data hosted page. It doesnt know the value that I entered on the form.

You're not showing us that though...so how can we help? As @snapey said, all you are doing is showing us variables being assigned values. You're not showing the form, or the route, or the controller method, etc. Show all of the relevant code.

Edit Your Profile
Update

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