TrederusMaximus

TrederusMaximus

Member Since 3 Years Ago

Germany

Developer at Germany

Experience Points 18,440
Experience Level 4

1,560 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 171
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

07 Jan
8 months ago

TrederusMaximus left a reply on Navbar: Vertical!! Why?

I have cut out the css at the top and then nothing was styled anymore. I think it may have some issue with the bootstrap version, maybe? I've tried to find a current version of bootsrap CDN:

https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css

and replace the old one on top of the app.php file but then styles did not load at all anymore.

TrederusMaximus left a reply on Navbar: Vertical!! Why?

@vilfago : I have tried Google Chrome and Microsoft Edge and the problem shows in both browsers.

TrederusMaximus left a reply on Navbar: Vertical!! Why?

Even if I copy an example form the web that's quite basic. For example the bootstrap example and replace my navbar with this example code it will still turn out to be screwed and appear in a vertical manner.

TrederusMaximus left a reply on Navbar: Vertical!! Why?

Sure... Here is my app.blade.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

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

    <title>{{ config('app.name', 'Trederus Maximus') }}</title>

    <!-- Styles -->
    <link href="/css/app.css" rel="stylesheet">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <!-- Scripts -->
    <script>
        window.Laravel = <?php echo json_encode([
            'csrfToken' => csrf_token(),
        ]); ?>
    </script>
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-default navbar-static-top">
            <div class="container">
                <div class="navbar-header">

                    <!-- Collapsed Hamburger -->
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
                        <span class="sr-only">Toggle Navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>

                    <!-- Branding Image -->
                    <a class="navbar-brand" href="{{ url('/') }}">
                        {{ config('app.name', 'Trederus Maximus') }}
                    </a>
                </div>

                <div class="collapse navbar-collapse" id="app-navbar-collapse">
                    <!-- Left Side Of Navbar -->
                    <ul class="nav navbar-nav">
                        <li><a href="{{ url('/general') }}">{{ ucfirst(trans('messages.general')) }}</a></li>
                        <li><a href="{{ url('/plantprofiles') }}">{{ trans('messages.plantProfiles') }}</a></li>
                        <li><a href="{{ url('/genera') }}">{{ ucfirst(trans('messages.genera')) }}</a></li>
                        <li><a href="{{ url('/species') }}">{{ ucfirst(trans('messages.species')) }}</a></li>
                        <li><a href="{{ url('/amorphophallus') }}">Amorphophallus</a></li>
                    </ul>

                    <!-- Right Side Of Navbar -->
                    <ul class="nav navbar-nav navbar-right">
                        <!-- Authentication Links -->
                        @if (Auth::guest())
                            <li><a href="{{ url('/login') }}">Login</a></li>
                            <li><a href="{{ url('/register') }}">Register</a></li>
                        @else
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                                    {{ Auth::user()->name }} <span class="caret"></span>
                                </a>

                                <ul class="dropdown-menu" role="menu">
                                    <li>
                                        <a href="{{ url('/logout') }}"
                                            onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                            Logout
                                        </a>

                                        <form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
                                            {{ csrf_field() }}
                                        </form>
                                    </li>
                                </ul>
                            </li>
                        @endif
                    </ul>
                </div>
            </div>
        </nav>

        @yield('content')
    </div>

    <!-- Scripts -->
    <script src="/js/app.js"></script>
</body>
</html>

TrederusMaximus started a new conversation Navbar: Vertical!! Why?

My navbar appears in a vertical manner. I can not manage to fix this. The navbar is defined in app.blade.php.

I'm using Laravel 5.7.13.

The Bootstrap CSS seem to be loading from the app.blade.php file. Is there any more CSS JS that is required in order to show the navigation properly?

Thanks in advance.

19 Dec
1 year ago

TrederusMaximus left a reply on Heart Of The Date Format

@delzep - Happy this helped!

TrederusMaximus left a reply on How To Call Postgresql Stored Procedure In Laravel 5

It looks like you did not give any parameters although the function definition has quite a few parameters defined. That generally causes the error "Undefined function: 7 ERROR: function create_jabatans() does not exist".

25 Sep
1 year ago

TrederusMaximus started a new conversation Total Confusion About JS Bower, Webpack, Gulp, Babel Etc.

Hello community,

I need your help! I've started off as a backend developer and have been doing that for quite some time. Now I want to battle the front end but I'm having my difficulties getting myself structured.

I wrote some vanilla JS in my project and have now decided to switch the code to VUE and latest ES2015 syntax in oder to tidy things up. The vanilly JS just got too messy and too difficult to maintain and extend.

Over the course of the project so far I have installed bower and also pulled in some stuff with NPM. Mainly JQuery and some other bootstrap stuff for smaller frontend solutions. I have to admit I did not really know what I was doing but got it working at the end.

Now I have come to the point where I want to structure my frontend stuff and finally get an indea from top to bottom about what's actually going on.

Implementin the VUE components has already tidied up stuff quite a bit but now I see that Jeffrey way is using webpack in the tutorials. I also will need babel as I only got stuff working in Chrome. In IE I've tried the page but things wont show.

Which leads to my question:

What is a decent setup for VUE and JS in general? No I have gulp, bower, npm running. Do I also need webpack or can I replace some stuff. Can someone suggest a tutorial or similar which gives a step by step explanation of how the JS stuff is best embedded within a modern web project. I'm sure there are tons of ways & opinions but I guess I need to get sarted somehow to be able to move forward.

Thanks so much already. I am looking forward to some learing! :-)

06 Sep
2 years ago

TrederusMaximus left a reply on Function Not Executed - First Steps Vue - Help Needed!

Okay - I found the problem! The CDN link contained a Vue version that was too old. I have now updated to: https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js

and everything works just fine...

TrederusMaximus started a new conversation Function Not Executed - First Steps Vue - Help Needed!

Hello guys,

I've just started learning Vue and started doing the Vuecasts series by Jeffrey Way.

However I have problems getting the following to work:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="belowImageId">

        <ul>
            <li v-for="book in books" v-text="book"></li>
        </ul>

        {{ foo }}
        <input type="text" id="inputId" v-model="foo">

        <button id="buttonId">Add Book</button>

    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.js"></script>
    <script>
        var app = new Vue({
            el: '#belowImageId',

            data:{
                foo:'bar',
                books: ['one', 'two', 'three', 'four']
            },

            mounted(){
                alert('mumu');
            }
        });
    </script>

</body>

The altert won't show. I do not know why?! Is ES2015 natively supported by Vue? Or do I have to get some more dependencies going? PHP-Storm is also complaining that method definition shorthands are not supported by the current JS version.... Any ideas?

14 Aug
2 years ago

TrederusMaximus left a reply on Eloquent Sqlsrv Join Pagination Error

This should do the trick:

$accounts = Accounts::select('accounts.*')
->join('UsersData', 'Accounts.CustomerID', '=', 'UsersData.CustomerID')
 ->simplePaginate(20);
 return view('accounts', compact('accounts'));

23 Feb
2 years ago

TrederusMaximus left a reply on How To Get The SQL Right?

I finally got it right. So I thought I'll share the results here in case other people get stuck with similar problems:

$query = Order::whereIn('id',
function($query) use ($request){
    $query->select('id')
        ->from(with(new Order)->getTable())
        ->where('content', 'like', '%' . $request->get('search_key') . '%')
        ->orWhere('orderNumber', 'like', '%' . $request->get('search_key') . '%')
        ->orWhere('description', 'like', '%' . $request->get('search_key') . '%');
    })
    ->where('customerId', '=', $user->getCustomerId());

TrederusMaximus left a reply on How To Get The SQL Right?

I think I'd be fine if someone will tell me how to turn this SQL:

select * from
(select * from orders where content like '%String%'
or orderNumber like '%String%'
or description like '%String%') as sq
where customerId = '123456'

into an Eloquent query. I want to pre-select all records that match the search results. And then in the 2nd step get those filtered down for a certain customer.

15 Feb
2 years ago

TrederusMaximus left a reply on How To Get The SQL Right?

Can you explain in some more detail? After reading about query scopes I do not get how they could be applied to this problem?!

TrederusMaximus left a reply on How To Get The SQL Right?

I'm on Laravel 5.2 - does that work equally well?

TrederusMaximus started a new conversation How To Get The SQL Right?

Hello all,

I am working on a search but have the problem with getting more than one Keyword to be searched as the ->orWhere() screws it. I think I need to implement a sub query but do not really know how to manage. I also only want all the orders that have a logo attached.

Here is the code I have at the moment:

        $query = Object::where('date', '<', $until)
            ->where('date', '>', $from)
            ->where('customer_id', '=', $user->getCustomerId());


        $searchKey = '';
        if ($request->exists('search_key') && ($searchKey = $request->get('search_key')) != ''){
            $query->where('number', 'like', '%' . $request->get('search_key') . '%')
                ->orWhere('other_number', 'like', '%' . $request->get('search_key') . '%')
                ->orWhere('content', 'like', '%' . $request->get('search_key') . '%');
        }

        $orders = $query->with('logos')->has('logos')->paginate(20);

Any ideas?

19 Jan
2 years ago

TrederusMaximus left a reply on Design Of Object - Your Ideas Needed!

@martinbean : This helped me to build the solution I want - thanks! :-)

17 Jan
2 years ago

TrederusMaximus started a new conversation Conditional Methods Based On Type?

Hello,

is there a good way to design conditional methods? I want to have an Article that provides certain methods and then I have article types e.g. "Base", "Specialarticle", "Veryspecialarticle".

I need:

Article->getPrice();

Article->getSpecial(); //only available if the article is of type "Specialarticle"

Article->getVerySpecial(); //only available if the article is of type "Veryspecialarticle"

Article->getVerySpecial() on an article of

if the Article is of type "Base" would make no sense, as it does not have the special infomations avaialble to process the request.

Now I have solved the problem by subclasses that extend the base article class but I have the problem that I want to simply get myself a collection of articles that are in a group eg. "ArticlesForSale". I want to receive all articles with possibly several different types that belong to the group. Then I need different methods to be available to the articles depending on their type.

Any ideas how to handle this? Any ideas are welcome!

TrederusMaximus left a reply on Design Of Object - Your Ideas Needed!

I think the problem is that I am trying to get a collection of Articles where the instances would be mixed:

Articlegroup::where('id', '=', Articlegroup::ORDERABLE)->first()->articles()->get()

The idea is that articles that can be ordered are all members of the group "orderable". That means that this group will contain both, special and veryspecial articles. Hence the returned collection would have to hold both kinds of instances.

I guess that's not possible so I would have to find an alternative solution...

TrederusMaximus left a reply on Design Of Object - Your Ideas Needed!

@martinbean I am trying to folllow your approach to see where it gets me. Now I've overwrittern the newFromBuilder method as suggested but runnning into the following error:

Cannot use object of type stdClass as array

Any idea?

TrederusMaximus left a reply on Design Of Object - Your Ideas Needed!

I also want to ask for a list of articles:


$articles = getArticlesByGroup('orderable');


and this group my contain articles of different types e.g. 'special' and 'veryspecial' articles.

The veryspecial article will provide more methods then the special article, so I will need a way of getting all articles at once but then later be able to call the methods unique to every article type.

TrederusMaximus started a new conversation Design Of Object - Your Ideas Needed!

Hello all,

I want to build a more complex article structure where I have a basic article and more special ones:

classes:

  • Article
  • SpecialArticle
  • VerySpecialArticle

I designed and abstract class Article and the other 2 inherit from that one.

I'm also storing an article type:

ArticleTypes: id: 0 = special id: 1 = veryspecial

Now I want to do something like:

getArticle($id) and get the right instance depending on the article type. If it is a special article I want an instance of SpecialArticle and so on...

What do you guys think would be the best way to tackle this problem?

Thanks for your ideas!

19 Dec
2 years ago

TrederusMaximus left a reply on Best Place For Comparing Min And Max Values?

Thanks,

how exactly do I implement it there? There is one function rules that returns an array of rules and another for user authentication.

Can I grab the entered abount and validate by sth. like:

$articleId = $this->get('articleId');//from the request 
$amount = $this->get('amount');//from the request
if ($amount < Article::getById($articleId)->getMinAmount){
return->back()-wiith('status', 'Min amount not reached');
}

TrederusMaximus started a new conversation Best Place For Comparing Min And Max Values?

Hi all,

I am working on some validation on an article where I want to compare the entered value for the required amount with the min. amount that is required for a certain article. I have a method getMinAmount defined on the article class.

Where is the best place to do this validation? Can I place this somewhere in the request I created (StoreArticleRequest extends Request)? Or should that go into the controller?

Thanks guys!

07 Dec
2 years ago

TrederusMaximus left a reply on Mail Queue Handling - Problem "payload" In DB Exists - NOT HANDLED! - How Is Payload Processed?

Pushing jobs onto the queue is no problem and I can see the jobs in the DB.

This looks like that:

{"job":"[email protected]","data":{"view":"emails.ape_profile","data":{"textAbove":"Testtext \u00fcber dem Angebot bearbeitet","ape":"::entity::|App\\Ape|69","textBelow":"Testtext unter dem Angebot bearbeitet","signature":"Test-Signatur bearbeitet"},"callback":"C:32:\"SuperClosure\\SerializableClosure\":524:{a:5:{s:4:\"code\";s:228:\"function ($message) use($fromEmail, $toEmail, $subject, $attachments) {\n    $message->from($fromEmail)->to($toEmail)->subject($subject);\n    foreach ($attachments as $attachment) {\n        $message->attach($attachment);\n    }\n};\";s:7:\"context\";a:4:{s:9:\"fromEmail\";s:18:\"[email protected]\";s:7:\"toEmail\";s:18:\"[email protected]\";s:7:\"subject\";s:23:\"Test Betreff bearbeitet\";s:11:\"attachments\";a:1:{i:0;s:17:\"c:\\temp\\ape69.pdf\";}}s:7:\"binding\";N;s:5:\"scope\";s:14:\"Mailers\\Mailer\";s:8:\"isStatic\";b:0;}}"}}

However, if I let the queue:work command in the console the only thing that happens is that the "attempts" counter is raised by 1 in the DB. Jobs are not processed.

Does "job":"[email protected]" mean that I have to create a new Job "mailer" that implements a method "handleQueuedMessage"?

I also opened the class Illuminate\Mail\Mailer and saw that this one implements the method "handleQueuedMessage". Just now I suppose that this is what should be called... Correct?

30 Nov
2 years ago

TrederusMaximus started a new conversation Mail Queue Handling - Problem "payload" In DB Exists - NOT HANDLED! - How Is Payload Processed?

Hello,

I have created a class Mailer:

namespace Mailers;

use Illuminate\Support\Facades\Mail;

abstract class Mailer{

    public function sendFromTo($fromEmail, $toEmail, $subject, $view, $data = [], $attachments = [])
    {
        //@Todo: add to queue
        $res = Mail::queue($view, $data, function ($message) use ($fromEmail, $toEmail, $subject, $attachments) {
            $message->from($fromEmail)
                    ->to($toEmail)
                    ->subject($subject);

            foreach ($attachments as $attachment){
                $message->attach($attachment);
            }
        });
    }
}

and as you can see I am using the Mail::queue method to push those emails onto the queue.

I have set up the queue as stated in the documentation by using the php artisan commands recommended.

I can also see the jobs in the DB (using the database driver).

If I know run the command

php artisan queue:work

It runs without any success message and just finishes. If I keep running it again and again the "attemps" within the DB increase if I have a look. To me that means sending fails.

Under "payload" within my DB I can see sth like:

"job":"[email protected]"

So where is this handleQueuedMessage function defined and may I have a conflict as I defined my own mailer class?

I do not know how to get the mails sent after they have been queued. however, if I use the normal send command mails are being sent normally...

Any hints would be appreciated!

Thanks in advance...

TrederusMaximus left a reply on Select Tag To Tag In PHP-Storm

@tomi Perfect! That was it! I found on my Windows machine it is crtl + w! Thanks a lot! Makes my day. :-)

TrederusMaximus left a reply on Select Tag To Tag In PHP-Storm

I'm on a Windows machine. Seems to be sth. different.

TrederusMaximus started a new conversation Select Tag To Tag In PHP-Storm

Hi guys,

I saw Jeffrey selecting all code in between two tags. I can't find how to do that just now. Can anyone give me a hint?

If I have sth. like:

<div>
 some code, further sub divs, 'n stuff
</div>

I want to just click (or whatever is required) the outside div and get opening and closing div as well as all in between selected without scolling down trying to find the closing one (Where there is more code than in this example).

Thanks in advance guys! :-)

15 Nov
2 years ago

TrederusMaximus left a reply on Sweetalert SWAL Is Not Defined - After NPM Install

PS: even if I try:

var swal = require('sweetalert');

I get the message: Uncaught ReferenceError: require is not defined(…)

I have the feeling it does not even include the NPM stuff. How can I check for that? How does all the NPM gets loaded into my HTML page?

TrederusMaximus started a new conversation Sweetalert SWAL Is Not Defined - After NPM Install

Hello all,

I am still relatively new to using NPM so I do not really understand what the porblem is.

I have installed sweetalert by the following command:

npm install sweetalert --save

Now it appears if I do npm list and I can also find it within the node_modules folder.

However: If I try to call it this way:

    <script>
         $('button#orderButtonId').on('click', function(){

          swal({
            title: "Are you sure?",
            text: "Die Bestellung wird aufgegeben und es können keine weiteren Artikel hinzugefügt werden!", type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Ja, Bestellung aufgeben!",
            closeOnConfirm: false
          },
               function(){
            $("#orderFormId").submit();
          });
        })
    </script>

I get the message:

73:127 Uncaught ReferenceError: swal is not defined(…)

Any ideas what I can do?

Thanks in advance! :-)

01 Nov
2 years ago

TrederusMaximus left a reply on Remember The Form Input Even If Validation Fails

Thanks @InaniELHoussain ! I thought I saw sth. like that in one of the Laracasts but did not really remember. That helped! :-)

TrederusMaximus started a new conversation Remember The Form Input Even If Validation Fails

Hi all,

I am having the proplem that I have forms that are quite complex. After filling them out I submit and then all the form data is gone if validation fails (I forgot one single entry) and I have to start all over again.

I'm sure there's an easy way to remember all the input even if validation failed such that I only have to provide the forgotten fields and submit again.

Anyone knows?

Thanks in advance! :-)

17 Oct
2 years ago

TrederusMaximus left a reply on Heart Of The Date Format

Thanks to every single one that contributed to this thread. I finally got it working and I will document my solution here in order to help people with the same problem. I did the following:

  • Go to the MS SQL SERVER DB#
  • Create a new Login
  • Set the default language for this login to the desired language. This way you do not have to set the language settings globally and you can also set the default DB for your new login such that you only work with your DB in the language you require. In laravel I did a global search using PHP_Storm and changed all the format strings to 'Y-m-d H:i:s.u'. Make sure you do not forget the very last '.u' as I got the error message "trailing data" without that.

Now Laravel and MS SQL Server have the same date format and I can continue my work!

PS: Go to config/database.php and add

'pooling' => false,

to your MS SQL SERVER-DB connection definition if you get an invalid DB handle returned after chaning to the new login unser!

14 Oct
2 years ago

TrederusMaximus left a reply on Heart Of The Date Format

I have tracked the problem down to the DB. MS SQL Server accepts date formats in the format 'Y-d-m H:i:s' and outputs them in the format 'Y-m-d H:i:s'. What is that?! Even if that exceeds the scope of Laravel - I'd be happy for any hints on how to make the accepted in- and output formats in MSSQL equal!

TrederusMaximus left a reply on Heart Of The Date Format

Okay... changing the format in the DB is no real option. That means I need to find a way to get it done through Laravel. Can't I just say somewhere Carbon this: 'Y-d-m H:i:s' is your date format for all inputs and all outputs?

TrederusMaximus left a reply on Heart Of The Date Format

Laravel is using Carbon but that relies on the SqlServerGrammar.php that implements a funtion getDateFormat();

That's the way it looks within SqlServerGrammar.php:

    /**
     * Get the format for database stored dates.
     *
     * @return string
     */
    public function getDateFormat()
    {
        return 'Y-m-d H:i:s.000';
    }

I've changed that to my required format and then it wrote the data into the DB. But now I am having problems getting the data out! This comes due to Carbon not being able to parse the incoming timestamp.

ErrorException in Carbon.php line 425:
Trailing data (View: C:\cw\PhpstormProjects\asweb\resources\views\users\index.blade.php)

Now I'm considering changing the format in the DB but after looking into that for some time now I'm also not sure if that's an easy fix.

TrederusMaximus started a new conversation Heart Of The Date Format

Hello all,

I have to work with MS SQL Server which means that I need to change the date format from "Y-m-d H:i:s" to "Y-d-m H:i:s" .

I have found the Model function getDateFormat():

    protected function getDateFormat()
    {
        return $this->dateFormat ?: $this->getConnection()->getQueryGrammar()->getDateFormat();
    }

and then followed it down to "getDateFormat()":

    /**
     * Get the format for database stored dates.
     *
     * @return string
     */
    public function getDateFormat()
    {
        return 'Y-d-m H:i:s';
    }

But if I change the format here that does not seem to have any influence of the date format. I know that there is a way by overriding the getDateFormat() funtion in the model but as I would have to do that for every model and also have other code that I've just required via composer that relies on the underlying date format structure I'd like to change it at it's very heart.

Any ideas and/or experience what would be the best way?

Thanks in advance! :-)

29 Sep
2 years ago

TrederusMaximus started a new conversation Image Paths - The Right Way?

Hello all,

I'm doing my first laravel project and I am trying to get my image paths right:

I've added the storage path to this function as I have saved my pictures under storage/images


if (! function_exists('public_path')) {
    /**
     * Get the path to the public folder.
     *
     * @param  string  $path
     * @return string
     */
    function public_path($path = '')
    {
        return app()->make('path.public').($path ? DIRECTORY_SEPARATOR.$path : $path);
    }

    /**
     * Get the path to the storage folder.
     *
     * @param  string  $path
     * @return string
     */
    function storage_path($path = '')
    {
        return app()->make('path.storage').($path ? DIRECTORY_SEPARATOR.$path : $path);
    }
}

Then I am trying (on my local dev computer) to show the pics within the page like that:


<img src="{{ storage_path() . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.jpg'}}"  width="86" height="30">

But the image won't show - path is right - if I copy the path and paste it in a new browser tab it finds the image.

However if I cut the path to the relative path:


<img src="'..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage' .  DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.jpg'}}"  width="86" height="30">

it will show. But The relative path obviously changes as I dive deeper into the folder structure and I do not want to adjust that every single page.

What is a good way to solve that problem? How do you handle that? Thanks a lot for answers already!

06 Sep
3 years ago

TrederusMaximus left a reply on Problem With CSRF - VerifyCsrfToken.php Line 67

I have solved the issue. I was having a wrong path in the link and hence the mismatch exception!

TrederusMaximus left a reply on Problem With CSRF - VerifyCsrfToken.php Line 67

I have now also compared the value of the token in the session file and the one which gets taken into the form after I add csrf_field() and they match!! I really do not know what the problem is.

Does anyone know where exactly those 2 values are being compared within the code such that I can track that down?

TrederusMaximus left a reply on Problem With CSRF - VerifyCsrfToken.php Line 67

The folder storage/framework/sessions is writeable. As far as I understood I did things as they're supposed to be. Have the csrf_field() inside my form tags and sessions can be written... Problem persists.

05 Sep
3 years ago

TrederusMaximus left a reply on Problem With CSRF - VerifyCsrfToken.php Line 67

My routes look like this:

Route::get('articles/{article}/edit', '[email protected]');
Route::patch('articles/{article}', '[email protected]');

In my session.php is says:

'driver' => env('SESSION_DRIVER', 'file'),

Is that info sufficient?

TrederusMaximus left a reply on Problem With CSRF - VerifyCsrfToken.php Line 67

The thing is that if I look into the source on my page the token seems to be replaced in the correct way. Once I submit the form I get the mismatch exception. I now wonder what it the token compared to? Do I have any way to dump both values and see where the mismatch is? I've just started with Laravel and still do not know much about CSRF.

TrederusMaximus left a reply on Problem With CSRF - VerifyCsrfToken.php Line 67

I've tried that but that just seems to break my code. What was the idea behind that suggestion?

TrederusMaximus started a new conversation Problem With CSRF - VerifyCsrfToken.php Line 67

Hello,

I am trying to submit a simple form :

<div class="row">
    <form name="article" method="POST" action= "/ASweb/public/articles/{{$article->id}}">
        {{--@Todo: FIND OUT WHY IS THIS NEEDED?!!--}}
        {{ csrf_field() }}
        {{ method_field('PATCH') }}
        

        <div class="col-md-4">
            <textarea name="description" class="form-control">{{$article->description}}</textarea>
        </div>
        <div class="col-md-8">
            <button type="submit" class="btn btn-primary">Save</button>
        </div>

    </form>
</div>

But I am always getting the following error message:

TokenMismatchException in VerifyCsrfToken.php line 67:

As you can see I have already included the {{ csrf_field() }}. I did this as I read that it will fix this issue and the correct token will be matched. But the problem persists. I am trying to do a post that I convert to a patch as suggested in the "Laravel from scratch" lectures and then I simply want my controller to update the fields and return to the page. Nothing special.

Any hints are appreciated! THANKS! :-)

02 Sep
3 years ago

TrederusMaximus left a reply on Routes Parameter Problem

Bam - that's the way it goes sometimes... You've just saved my day bobbybouwmann! Thanks! :-)

TrederusMaximus started a new conversation Routes Parameter Problem

Hello,

I'm having some weird behaviour here. I've tried to set up a route like this:

Route::get('articles/{article}/pricescales/{pricescale}', '[email protected]');

but only get it working if I reduce to this:

Route::get('pricescales/{pricescale}', '[email protected]');

I found that the article ID (which is a sting based ID) gets picked up and given to my PricescalesController instead of the Pricescale model.

Why does laravel try to get the Pricescale model based on the articel ID if I try it this way?

TrederusMaximus left a reply on MS SQL SERVER & LARAVEL - Reloaded

I found a solution that seems to work myself now:

In the php.ini I set the default timezone like this:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "US/Central"
31 Aug
3 years ago

TrederusMaximus started a new conversation MS SQL SERVER & LARAVEL - Reloaded

I'm quite new to Laravel and I've spent hours now trying to fix an issue with Laravel and MSSQL SERVER.

It all started with the problem that as I tried to save my data to DB and got the error message:

SQLSTATE[22007]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]
Bei der Konvertierung eines nvarchar-Datentyps in einen datetime-Datentyp liegt der Wert außerhalb des gültigen Bereichs. 
(SQL: update [articles] set [description] = rgt, [updated_at] = 2016-08-31 13:30:31.000 where [id] = testID1)

I've searched through the web and found several solutions including creating a BaseModel that overrides the dateformat method, setting the dateformat in the model and similar. I did this and first it seemed to work but once I tried the same on the 2nd model I got antoher problem:

ErrorException in Carbon.php line 425:
A textual month could not be found
Unexpected data found.
Unexpected data found.
Unexpected data found.
The format separator does not match
A meridian could not be found (View: C:\cw\PhpstormProjects\ASweb\resources\views\articles\edit.blade.php)

Now I do not know what to do anymore. Even just tryign to load a simple view causes a crash with the above error message. I do not even get the chance to save anymore. Now it seems changing adding:

protected $dateFormat = 'M j Y h:i:s:000A';

to the model breaks it all.

If anyone has an idea I would be more than happy!