Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

Phread

Phread

Member Since 4 Months Ago

Ohio

Experience Points
3,710
Total
Experience

1,290 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
22
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 1
3,710 XP
Oct
25
1 month ago
Activity icon

Replied to How To Make A Subdomain Like Sa.domain.com And Display Specific Data On It ? PHP

Maybe I am missing the question, but it seems as if you could have the domains point/use the same database, each domain defining the specific qualification(s) you want.

Define the qualification's value in either the .env file OR in the config/app.php file (preferred choice) This would allow you to specify the qualification for each of your domains you currently have and may add in the future.

And, for the domains which would not have any specific qualification(s) you could have it defined as "1=1" in .env or config/app.php.

Activity icon

Replied to Joining Table From Different Datatbase

It may be easiest if you were to export the table from the one database into a table in the new database and join the 2 of the tables together. As an example:

  • Database 1 has a table called banks
  • Database 2 has a table called banks
  • Export banks from Database 2
  • Import the banks data into new table called banks2
  • Join the 2 tables in your query and go for it....

The following were 2 answers I found via google, 8+ years ago... BTW, the following is an answer from 2012

https://dba.stackexchange.com/questions/24054/query-two-sql-server-databases-on-two-different-servers

And this is an answer from 2010

https://bytes.com/topic/php/answers/721490-connecting-two-mysql-tables-different-databases

The last one has an answer which seems to be pretty darn good. Sorry, but I do not have a way to verify this syntax or approach.

	
brandoo
this script connects at two databases, each one located on a different server, and clones the source_table from the second database to the destination_table located on localhost (first database)


<?php
$host1="localhost"; // destination
$base1="first_database";
$user1="root";
$password1="";

$host2="192.168.0.1"; //source
$base2="second_database";
$user2="root";
$password2="xxx";



$conection1 = @mysql_connect($host1, $user1, $password1) 
or die("Error reaching destination<br>".mysql_error()." nr eroare: ".mysql_errno());
print "Succesfuly connected 1! <br>";

$Db1 = @mysql_select_db($base1, $conection1)
or die("Error reaching destination database:<br>" . mysql_error(). "<br>" . mysql_errno());
print "Database1 reached!<br>"; 




$conection2 = @mysql_connect($host2, $user2, $password2) 
or die("Error reaching source<br>".mysql_error()." nr eroare: ".mysql_errno());
print "Succesfuly connected 2!<br>";

$Db2 = @mysql_select_db($baza2, $conexiune2)
or die("Error reaching source database:<br>" . mysql_error(). "<br>" . mysql_errno());
print "Database2 reached!!<br>"; 



$query = 'create table destination_table select * from second_database.source_table'; 
//echo "<br>".$query."<br>"; 
$result2 = mysql_query($query2, $conection1) or die('Query failed: ' . mysql_error().'||'.mysql_errno());



mysql_close($conection1);
mysql_close($conection2);
?>
Oct
21
1 month ago
Activity icon

Replied to Change Laravel DataTable Text

I believe the following portion of the Laravel Documentation explains how to accomplish this task.

https://laravel.com/docs/8.x/pagination#customizing-the-pagination-view
Oct
19
1 month ago
Activity icon

Replied to Laravel 8.x 419 "CSRF Token Mismatch"

I apologize for not replying sooner, I didn't see your question to me.

I believe that it is still required. However, given that it has been 2 weeks, it would be greatly appreciated if you could share what you ended up having do.

Oct
15
1 month ago
Activity icon

Replied to Prevent White Space In The Input Not Working

JavaScript to allow numbers only. It will NOT allow for spaces.

    <SCRIPT TYPE="text/javascript">
        <!--
        function numbersonly(myfield, e, dec)
        {
            var key;
            var keychar;
            if (window.event)
                key = window.event.keyCode;
            else if (e)
                key = e.which;
            else
                return true;
            keychar = String.fromCharCode(key);
            // control keys
            if ((key==null) || (key==0) || (key==8) ||
                (key==9) || (key==13) || (key==27) )
                return true;
            // numbers
            else if ((("0123456789").indexOf(keychar) > -1))
                return true;
            // decimal point jump
            else if (dec && (keychar == "."))
            {
                myfield.form.elements[dec].focus();
                return false;
            }
            else
                return false;
        }
        //-->
    </SCRIPT>

On the field

onkeypress="return restrictInput(this, event, integerCommaOnly);"
Oct
10
1 month ago
Activity icon

Replied to Sort An Laravel Encrypted Field

I was hoping for a magic solution... And this will have to be it. Thank you!

Activity icon

Started a new Conversation Sort An Laravel Encrypted Field

I have a field which is stored in a MySQL db as a Laravel encrypted value. I would like to sort on the field, but given that it is encrypted I don't see a way to do this..... I am not allowed to save the field without it being encrypted.

Suggestions ?

Activity icon

Replied to How To Show Alert To Specific User?

I believe the following will answer your question. BTW, I use Swal due to the way the Alert looks. This is a snippet of the validation I use for my forms. I do use the "theCount" variable to pre-pend the error count #.

<script>
    function validateform(){
        var toUserID=document.myform.to_user_id.value;
        var fromUserID =document.myform.from_user_id.value;
        var thecount=0;
        var thealert="";
        var btnval = "";

        if (toUserID == fromUserID){
            thecount = thecount + 1;
            thealert = "User ID From is the same As User ID 2");
        }
 
        if(thecount > 0) {
            Swal.fire({
                showCloseButton: true,
                confirmButtonText: btnval,
                footer: thealert,
                confirmButtonColor: '#dd3333',
                backdrop: `rgba(77, 0, 0, .35)`
            });
            return false;

        }
    }
</script>
Oct
09
1 month ago
Activity icon

Replied to Is B2b Possible With Laravel?

Purple, the answer to all questions.

Oct
04
1 month ago
Activity icon

Replied to Laravel 8.x 419 "CSRF Token Mismatch"

I believe you need to add

 enctype="multipart/form-data" 

in the form method.

<form method="POST" enctype="multipart/form-data" ......




When you make a POST request, you have to encode the data that forms the body of the request in some way.
Oct
02
1 month ago
Activity icon

Replied to Laravel 7 Vs Laravel 8 Dilemma

I would go to 8. Listen to the following Video which will explain how you, if you reallllly want, could stay with the ui version from 7.x and lower. Just remember, ui is deprecated in 8.x and as such may not be available for the next major version. The video gives an amazing description of the changes, what each will do, which one makes sense depending upon what you are wanting to do, etc.

https://www.youtube.com/watch?v=NuGBzmHlINQ

Oh yeah, I would highly recommend that you "subscribe" to the channel.

Activity icon

Replied to Datepicker For Laravel 7 & Bootstrap 4?

I use When.datepicker - Date Range Picker, available on codecanyon. It had every feature I was looking for and more. It has a TON of different ways to use the date and/or date/time and was a breeze for me to start using. There is a $9 cost.

https://codecanyon.net/item/whendatepicker/22418308

I did try a variety of Bootstrap & js versions, but they came up short on the features I wanted and I kept running into limitations that made them useless for me.

Activity icon

Replied to How To Get The Difference Between Employment Date And Current Date In Month

or via SQL:

DB::raw('TIMESTAMPDIFF (YEAR,tableName.fieldName , CURDATE()) as main_age')

Just depends on where you want the work done.

Sep
23
2 months ago
Activity icon

Awarded Best Reply on Laravel Cache Available In A View

I have been thinking about this question for about a month before I finally gave up and posted this question.

I had an interesting conversation with my oldest son today about this. The more we chatted about this, the more we decided that it would be more efficient to pass the cache values to the view, but to qualify the passing of the cache values based on the Area being accessed (Banking, Credit Card, Investment, etc).

We also thought that it would be less of a hassle to take this approach than to deal with getting the information from cache in the view.

So, my question is now moot, but given some of the responses I thought I would share what I am doing.

The following is a snippet of the view:

CREATE OR REPLACE VIEW allRefView AS 
select "bank" as theArea, id, shortDesc, fullDesc from `zref_bankaddresstypes`
	union 
select "contact", id, shortDesc, fullDesc from zref_contactaddresstypes
	union 
select "creditcard", id, shortDesc, fullDesc from zref_creditcardaddresstypes
	union 
select "insurance", id, shortDesc, fullDesc from zref_investmentaddresstypes
         ;

The creation of the cache is in the GenericXref php file - like a Controller but it only creates the different caches:

    // \
    // The following will allow for creating one dataset from an existing database view.
    //  Column Explanation
    // =================
    // 1) theType = email, phone, etc
    // 2) theArea = Banking, Credit Card, Investment, etc
    // 3) shortDesc = Value to be displayed in the listbox, most of the time
    // 4) fullDesc = Value to be displayed in the listbox, for specific list boxes
    // /
    public function allRefs(){
        return cache()->remember('allRefView',60*60*24*7, function(){
            return DB::table('allreftypeview')
                ->select ('theType', 'theArea', 'id', 'shortDesc', 'fullDesc')
                ->get() ;
        });
    }

The following gets the cache values for all the reference values in the Controller.


        $setTheXref = new GenericXref();
        $allRef = $setTheXref->allXref();

The Controller then returns $allRef

 return .....  compact('allRefs'......));

Instead of passing the whole cache we will now qualify the cache to only deal with the Area being dealt with at the moment.

$allRef = $setTheXref->allXref()->where('theArea','=','Banking');

And then we can qualify it in the view as needed.

Thanks to everybody for their help and comments. They did have an impact on the approach.

Activity icon

Replied to Laravel Cache Available In A View

I have been thinking about this question for about a month before I finally gave up and posted this question.

I had an interesting conversation with my oldest son today about this. The more we chatted about this, the more we decided that it would be more efficient to pass the cache values to the view, but to qualify the passing of the cache values based on the Area being accessed (Banking, Credit Card, Investment, etc).

We also thought that it would be less of a hassle to take this approach than to deal with getting the information from cache in the view.

So, my question is now moot, but given some of the responses I thought I would share what I am doing.

The following is a snippet of the view:

CREATE OR REPLACE VIEW allRefView AS 
select "bank" as theArea, id, shortDesc, fullDesc from `zref_bankaddresstypes`
	union 
select "contact", id, shortDesc, fullDesc from zref_contactaddresstypes
	union 
select "creditcard", id, shortDesc, fullDesc from zref_creditcardaddresstypes
	union 
select "insurance", id, shortDesc, fullDesc from zref_investmentaddresstypes
         ;

The creation of the cache is in the GenericXref php file - like a Controller but it only creates the different caches:

    // \
    // The following will allow for creating one dataset from an existing database view.
    //  Column Explanation
    // =================
    // 1) theType = email, phone, etc
    // 2) theArea = Banking, Credit Card, Investment, etc
    // 3) shortDesc = Value to be displayed in the listbox, most of the time
    // 4) fullDesc = Value to be displayed in the listbox, for specific list boxes
    // /
    public function allRefs(){
        return cache()->remember('allRefView',60*60*24*7, function(){
            return DB::table('allreftypeview')
                ->select ('theType', 'theArea', 'id', 'shortDesc', 'fullDesc')
                ->get() ;
        });
    }

The following gets the cache values for all the reference values in the Controller.


        $setTheXref = new GenericXref();
        $allRef = $setTheXref->allXref();

The Controller then returns $allRef

 return .....  compact('allRefs'......));

Instead of passing the whole cache we will now qualify the cache to only deal with the Area being dealt with at the moment.

$allRef = $setTheXref->allXref()->where('theArea','=','Banking');

And then we can qualify it in the view as needed.

Thanks to everybody for their help and comments. They did have an impact on the approach.

Sep
21
2 months ago
Activity icon

Started a new Conversation Laravel Cache Available In A View

I created a cache in the login's Controller (assume they are all the reference tables's values) and would like for the cache to be available within the view. I understand that I can pass the cache to the View but that means I have to do that in every Controller and I may end up with over 100 Controllers.

I found in the documentation where we can create/add to a cache but I did not see a way to get the cache.

Thanks for the help!

Activity icon

Replied to Add URL Querystring As User Is Leaving Page

You could put the current query params in a session variable and use that the query if they happen to go back into the form. Each time there is a change in the query you could set the session variable to the new query qualification(s).

And just in case you have not dealt with "session".

        // \
	// If the session variable does NOT exist then set it to the current value.
	// Otherwise, remove the session variable and then set it to the current value.
	// 	Note:  I found that you don't need to use "Session::forget" in order to set the new 
	//		    value, but the doc I read was rather vague on needing this.  I just felt it was a
	//		    slightly safer approach.
	// /
        if (!Session::get('SessionVarHere')) {
            session::put('SessionVarHere', $varNameHere);
        } else {
            Session::forget('SessionVarHere');
            session::put('SessionVarHere', $varNameHere);
        }
Sep
20
2 months ago
Activity icon

Replied to Obfuscating URLs Securely

Alternative to the uuid/slug is:

 - Put the id in a hidden field.
     - I have used a field called "fortestpurposes" (or something that makes it appear that the field is just for junk) 
        to hold the entries id.
   - At one time I included randomly generated values before/after the real id's value to help hide the real id.  
      I finally realized that this was overkill and was causing more hassles then worthwhile.  
 - The Controller would use the hidden field's ID for the update/delete statements.  
      - Additionally, the Controller would also include the Users ID in the update/delete function.  
        - I would get the User's ID in the Controller, not allowing the User any knowledge of what their
          User ID is.
 - All of my tables which stored User data included a userID field (bigint).  

This approach stops the Users from being able to game the app by changing the ID in the url.   And if you wanted, you would use the ID passed in the URL, remove the hidden field, and perform the update/delete using the id passed in the url along with the User's ID.  Unless the entry belongs to them (User's ID), the update/delete wouldn't do anything.

Activity icon

Replied to Project Suggestion

Bug Tracking app, allowing to email notification of the bug's journey from inception to completion..... There are plenty of examples to get ideas of what others have done, what you like, don't like, and believe is missing.

This should give you a number of different areas of Laravel (Controllers, Views, web.php, error control/display, etc), Database, TailwindCSS (or other CSS), HTML, JavaScript, email, add-ons from trusted sources like Spatie.be, and so on....

This should keep you busy for at least a couple of days. :-)

Have fun!

Sep
16
2 months ago
Activity icon

Replied to How Can Get Last 10 Character Of String From Database

You have a number of ways to get the result you are looking for.

- Use siangboon's approach
  - It works.  I am not sure what databases it works for or if it matters for you.  
- Use php
   - substr()
      For more information: https://www.php.net/manual/en/function.substr.php
- Use Laravel
   - Make sure the length is greater then xxx
      - Str::length()
   - Get the substring using: Str::substr()
  - For more information: https://laravel.com/docs/8.x/helpers#method-str-length

I prefer either the db::raw or php. But, this is a preference and situation selection.

My personal preference is to perform the substring in php for multiple reasons:

1)  Invariably once I use db::raw I seem to need the same field to be used slightly different.      
2) I have all of my db queries (select, update, & delete) contained in 1 file.  The queries are 
     generally used for 1 Controller, BUT I have a couple that are used for multiple Controllers.
3) I prefer to not use functions that may be database specific.  You may need to look into this
    if you are concerned about using or moving to specific databases.  I am trying to be database agnostic,
   just incase I need to change for whatever reason.

So, in MY case I perform the sub string function in php. But, I do like siangboon's approach and would most likely use it over the other options.

Just to reiterate, there are multiple ways to accomplish your request. It seems to come down to a preference you feel most comfortable with.

Oh yeah, there is a way to execute php in a blade, but there were quite a few people that said to stay away from this feature if at all possible. Sorry, I don't remember the reasons....

Activity icon

Replied to You Can Save Me!

Hopefully the answer from the following URL will get you pretty darn close to what you are looking for. It appears that you need to parse address from the following "address" variable.

var address = results[0].formatted_address;


https://coderwall.com/p/ouofjg/getting-current-location-with-javascript

You could also use the following from Google for geocoding a variety of ways.

https://developers.google.com/maps/documentation/geocoding/overview
Activity icon

Replied to Dynamic Views (Like Products/<slug>) Do Not Work.

Some learn from their mistakes, their experiences, and/or from what other's mistakes and experiences.

This comment for you was uncalled for, it could be considered to be possibly unprofessional. Azoraque was asking for assistance in solving his problem(s). If you can't help, then I suggest that you may want to move on.

Your previous comments appeared to be a request for help to both understand and resolve the problem(s). It wasn't a request for somebody to smack him like this....

Activity icon

Replied to How Would I Display A CMS Theme Demo Within A Laravel Site Like Themeforest?

You could create screen captures, either putting them in a carousel OR display them on one page. You could allow them to click thru to the showcase websites with a preset username/password.

Imho, I think it could be a ton of work to replicate the website within your base CMS site, and I don't see anything to be gained to do this. This also keeps the maintenance down as you don't need to maintain the main site and the one you jiggered to work on your showcase site. You only have to redo the screen captures this way.

Activity icon

Replied to A Domain Name For My Social Network Startup.

There seems to be a science in creating company and websites names. I am not convinced that they work, at least not for me. So, the following is what I have used.

What do you want to do with the website ?
	- List 10
	- Put the 10 in order, most important at the top, least important at the bottom.
	- Without this list, imho, you can't ask anybody to give you feedback on the names AND
	  how do you determine the name if you don't know the goal of the website.
Who is the website for ?
	- Technical, non-tech, holy cow stupid, combination, etc
What do you envision the website to morph to ?
	- You may start with one idea, and then find out that you could include another Area.
		- Try to allow for this UNLESS it will only be for the originally intended purpose.
List names you can think of.  
	- I made my cutoff for this round at 20.  An arbitrary number that kept me boxed into the top
	  xx and not have to deal with hundreds of ideas.  I tried to make it a max of 10, but I couldn't do it.
Run the list by others to see and hear their reactions and to get their ideas.
Cut the total list to 20, again.
Put the names on sticky notes on a wall.
	- Put them on a wall next to each other
		- If possible, the wall should be clear of distractions, such as bricks or wallpaper.
Make a list for each name (Pros and Cons)
	- Remove 10 that have the most cons.  
Now the fun starts.
Beat the hell out of the remaining 10.  
	- Look and modify the Pros and Cons.
	- If you have competitors, use them for what you like and don't like, adding them to your list of
	  Pros and Cons.
Cut your list to 5.
	- Get feedback from others on them.  I used the same people for the feedback, giving them an
	  the reason and goal of the website.  Don't assume that they will remember.  They don't.  And
	  you may have modified the reasons you want to give them.
Put the list in order and start looking for websites.
	- I did this using the hosting provider I planned to use for the website.  I made a decision on
	  the technology I was going to use, Laravel, and picked one of the top 4 hosting providers
	  for Laravel.  That allowed me to buy the site from my hosting provider as I found the names that 
	  were available.  I lost a couple of the names due to not adhering to this..  AND it made it easier 
	  purchasing the names from the hosting provider I was going to use and not deal with transferring 
	  the name to another provider.
	- I purchased a couple of the website names just to make sure I had them and also to box in the name
	  I chose to keep others away from my website.  Kind like facebook.com & facebooks.com....
		- Yeah I spend a extra 0-200 by doing this, but it saved me from others taking names close to my 
		  website's name and then trying to sell the name to me at a premium.

Now, you have your top 5 names of the website you wanted and the top 5 website names you could get. Use one of them, develop the website on one of them (make it easy for you to change the name/logos, do the development in modules allowing for easier changing of names and logos). As you are doing the development you will most likely find one of the names that really fit what you have done and your goals.

In my infinite wisdom, I took a very similar approach for a previous website, EXCEPT I threw away everybody's suggestions & input and used the one I LOVED. I still LOVE the name, but it was so stark that I couldn't build my User base to make the site work. YourDeathDirections.com I killed the site. The replacement is YourPersonalInformation.com Much more subtle, but a very similar goal.

I would also suggest that you find and work with Mentors, making sure that you and the mentor know the rules for each other. If you don't know the rules of the game, it is much more difficult to play the game..... Given that you are having problems from the very beginning, you get where I am going with this....

This process can be maddening... But it sure is fun to look back to see how far you have come....

Have fun and all the best!!

Activity icon

Replied to How To Assign Value To Global Variable Outsie Of A Function

I use something like the following to dynamically add a new row. This also contains a section for getting values from an existing listbox for use in the new row's listbox. The above answers explain how to do the total math.


    /*
       Add a new Phone row
    */
    function addPhoneRow(tableID) {

        var table = document.getElementById(tableID);

        var rowCount = table.rows.length;
        var row = table.insertRow(rowCount);

        var cell1 = row.insertCell(0);
        var element1 = document.createElement("select");

        element1.name="PhoneKeepDel[]";
        element1.classList = "block form-select block w-full py-2 px-3 border border-gray-300 rounded-md shadow-md focus:outline-none focus:shadow-outline-blue focus:border-blue-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5";
        element1.options.add(new Option("Keep","RETAIN"));
        element1.options.selectedIndex = 1;
        element1.options.add(new Option("Delete","DELETE"));
        element1.options[0].selected="true";
        cell1.appendChild(element1);
        cell1.style.textAlign = "center";


        var cell2 = row.insertCell(1);
        cell2.innerHTML = rowCount;
        cell2.style.textAlign = "center";
        cell2.style.paddingLeft = "7px";

        var cell3 = row.insertCell(2);
        var element2 = document.createElement("select");
        element2.type = "select";
        element2.name = "phoneTypeID[]";
        element2.classList = "block form-select block w-full py-2 px-3 border border-gray-300 rounded-md shadow-md focus:outline-none focus:shadow-outline-blue focus:border-blue-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5";
	/*
		The following will get the values from a hidden listbox which contains all the values 
		allowed for the User to select from.  A variation of this could be used to get the values from each of 
	the existing rows.
	*/
        var options = document.getElementById('hidePhoneTypeID').options;
        for (var i = 0; i < options.length; i++) {
            element2.options.add(new Option(options[i].text, options[i].value));
        }
        /*
            element2.setAttribute('data-placement', 'right');
            element2.setAttribute('data-toggle', 'tooltip');
            element2.setAttribute('title', 'Enter the type of Phone number being entered.');
            element2.setAttribute('data-original-title', 'Enter the type of Phone number being entered.');
        */
        element2.options.selectedIndex = 0;
        cell3.appendChild(element2);

        var cell4 = row.insertCell(2);
        var element3 = document.createElement("input");
        element3.type = "text";
        element3.size = "20";
        element3.name = "thephonenbr[]";
        element3.placeholder = "Enter the Full Number";
        element3.className += ' textinput';
        element3.className += ' inputstl';
	/*
		The following value for the classList WILL be changed to use a global variable.  That
		would allow for the change to be made in ONE place instead of each of these functions.
	*/
        element3.classList = "mt-1 form-input block w-full py-2 px-3 border border-gray-300 rounded-md shadow-md focus:outline-none focus:shadow-outline-blue focus:border-blue-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5";
        /*
            element3.setAttribute('data-placement', 'right');
            element3.setAttribute('data-toggle', 'tooltip');
            element3.setAttribute('title', 'Enter the phone number which may contain the country code (a + in the front if you would like), dashed or spaces in order to make the phone number easier to read');
            element3.setAttribute('data-original-title', 'Enter the phone number which may contain the country code (a + in the front if you would like), dashed or spaces in order to make the phone number easier to read');
        */
        cell4.appendChild(element3);


        var element4 = document.createElement("input");
        element4.type = "hidden";
        element4.name = "thephoneid[]";
        element4.value=0;
        cell4.appendChild(element4);

    }
Activity icon

Replied to OnClick Execute Function

I would move the following to be above the loop. They do not need to be set more than once.

        <form action="{{ action('[email protected]') }}" method="POST">
            @csrf

One other change I would suggest is to add the following to your form action statement.

       enctype="multipart/form-data"

As an example:

     <form action="{{ action('[email protected]') }" method="GET" enctype="multipart/form-data">

Activity icon

Replied to Laravel DB Column Type About Help.

Long text will allow up to 4gb.

The following may help for other field length questions (at least for MySQL). BTW, I use "text" for all the fields which could contain a value from the encrypt functionality.

Available Column Types

The schema builder contains a variety of column types that you may specify when building your tables:

Command	Description
$table->bigIncrements('id');	Auto-incrementing UNSIGNED BIGINT (primary key) equivalent column.
$table->bigInteger('votes');	BIGINT equivalent column.
$table->binary('data');	BLOB equivalent column.
$table->boolean('confirmed');	BOOLEAN equivalent column.
$table->char('name', 100);	CHAR equivalent column with an optional length.
$table->date('created_at');	DATE equivalent column.
$table->dateTime('created_at');	DATETIME equivalent column.
$table->dateTimeTz('created_at');	DATETIME (with timezone) equivalent column.
$table->decimal('amount', 8, 2);	DECIMAL equivalent column with a precision (total digits) and scale (decimal digits).
$table->double('amount', 8, 2);	DOUBLE equivalent column with a precision (total digits) and scale (decimal digits).
$table->enum('level', ['easy', 'hard']);	ENUM equivalent column.
$table->float('amount', 8, 2);	FLOAT equivalent column with a precision (total digits) and scale (decimal digits).
$table->geometry('positions');	GEOMETRY equivalent column.
$table->geometryCollection('positions');	GEOMETRYCOLLECTION equivalent column.
$table->increments('id');	Auto-incrementing UNSIGNED INTEGER (primary key) equivalent column.
$table->integer('votes');	INTEGER equivalent column.
$table->ipAddress('visitor');	IP address equivalent column.
$table->json('options');	JSON equivalent column.
$table->jsonb('options');	JSONB equivalent column.
$table->lineString('positions');	LINESTRING equivalent column.
$table->longText('description');	LONGTEXT equivalent column.
$table->macAddress('device');	MAC address equivalent column.
$table->mediumIncrements('id');	Auto-incrementing UNSIGNED MEDIUMINT (primary key) equivalent column.
$table->mediumInteger('votes');	MEDIUMINT equivalent column.
$table->mediumText('description');	MEDIUMTEXT equivalent column.
$table->morphs('taggable');	Adds taggable_id UNSIGNED BIGINT and taggable_type VARCHAR equivalent columns.
$table->multiLineString('positions');	MULTILINESTRING equivalent column.
$table->multiPoint('positions');	MULTIPOINT equivalent column.
$table->multiPolygon('positions');	MULTIPOLYGON equivalent column.
$table->nullableMorphs('taggable');	Adds nullable versions of morphs() columns.
$table->nullableTimestamps();	Alias of timestamps() method.
$table->point('position');	POINT equivalent column.
$table->polygon('positions');	POLYGON equivalent column.
$table->rememberToken();	Adds a nullable remember_token VARCHAR(100) equivalent column.
$table->set('flavors', ['strawberry', 'vanilla']);	SET equivalent column.
$table->smallIncrements('id');	Auto-incrementing UNSIGNED SMALLINT (primary key) equivalent column.
$table->smallInteger('votes');	SMALLINT equivalent column.
$table->softDeletes();	Adds a nullable deleted_at TIMESTAMP equivalent column for soft deletes.
$table->softDeletesTz();	Adds a nullable deleted_at TIMESTAMP (with timezone) equivalent column for soft deletes.
$table->string('name', 100);	VARCHAR equivalent column with a optional length.
$table->text('description');	TEXT equivalent column.
$table->time('sunrise');	TIME equivalent column.
$table->timeTz('sunrise');	TIME (with timezone) equivalent column.
$table->timestamp('added_on');	TIMESTAMP equivalent column.
$table->timestampTz('added_on');	TIMESTAMP (with timezone) equivalent column.
$table->timestamps();	Adds nullable created_at and updated_at TIMESTAMP equivalent columns.
$table->timestampsTz();	Adds nullable created_at and updated_at TIMESTAMP (with timezone) equivalent columns.
$table->tinyIncrements('id');	Auto-incrementing UNSIGNED TINYINT (primary key) equivalent column.
$table->tinyInteger('votes');	TINYINT equivalent column.
$table->unsignedBigInteger('votes');	UNSIGNED BIGINT equivalent column.
$table->unsignedDecimal('amount', 8, 2);	UNSIGNED DECIMAL equivalent column with a precision (total digits) and scale (decimal digits).
$table->unsignedInteger('votes');	UNSIGNED INTEGER equivalent column.
$table->unsignedMediumInteger('votes');	UNSIGNED MEDIUMINT equivalent column.
$table->unsignedSmallInteger('votes');	UNSIGNED SMALLINT equivalent column.
$table->unsignedTinyInteger('votes');	UNSIGNED TINYINT equivalent column.
$table->uuid('id');	UUID equivalent column.
$table->year('birth_year');	YEAR equivalent column.

NOTE
----
TINYTEXT 256 bytes
TEXT 65,535 bytes ~64kb
MEDIUMTEXT 16,777,215 bytes ~16MB
LONGTEXT 4,294,967,295 bytes ~4GB

Activity icon

Replied to How Do I Pass User_id For Updating Perpose In Admin Page?

I wanted to hide the user_id for the User as they do not have any reason to know what it is. If anything, I felt it would be a security issue for them to know it, thus I do not keep the value in a hidden field on the form nor do I pass it as a parameter. So, I get the user_id in the __construct section of my Controllers. I HATE the database hit I get every time the Controller is accessed, but I prefer the security I feel I am getting.

BTW, the User in this App MUST be 18+, this the check for the 18+. I unfortunately needed to check this every form, each time they attempted to either retrieved, update, or delete. Additionally I also wanted to make sure they were logged in or it would cause issues in the code. I use the user_id in the update/delete functions to make sure that the User couldn't scam me by updating another User's data.

    // \
    // Create all the global variables.  Note: It is not possible to get the User's ID
    // due to this section being executed prior to middleware layer.  As such, we need to perform
    // the middleware function call.
    // /
    public function __construct()
    {
        $this->middleware(function ($request, $next) {
            if (!Auth::check()){
                return redirect('timeouttologin');
            } elseif (Session::get('user_age') < 18) {
                return redirect()->route('userprofile_edit');
            }
            $this->theUserID = Auth::id();
            Session::put('CntrlArea', 'ALL_YOUR');

            return $next($request);
        });
        $this->theArea = "whatever Are the user is in - This allows me to use the same Blade for driving the 
			forms header and some other items";
        $this->viewDir = "similar to the viewArea but has a different function";
	// \
	// BTW, you can access these variables as $this-> theUserID , $this->viewName, and $this->viewDir . 
	// /
}
Activity icon

Replied to Laravel 7 Vs Laravel 8 Dilemma

I started with 5.8, moved to 6, moved to 7, and my hosting provider upgraded my app to 8 which took me by surprise me and terrified me.

However, Taylor and group have done a remarkable job in making sure that the install/upgrade went very smooth, and the upgrades don't cause harm. Had I not received notification from the host provider I am not sure I would have known for a couple of weeks.

I updated my development/testing environment and had NO issues.

I am not currently using Jetstream, but I think there is a very good chance I will due to the built-in authentication feature.

As for TailwindCSS, I LOVE it!!! I started with Bootstrap, but it just seemed to be clunky (drum brakes compared to Disk brakes). It worked, but very unimpressed with it. Once I started with TailwindCSS, I was hooked. Parts of it are overwhelming for me, but there are plenty of resources to help and to find examples from. And, you can have both Bootstrap & Tailwind in the same app. I still have some remaining bootstrap, but I have replaced ~99% with Tailwind.

The TailWind group created a site which contains quite a few UI examples that have been a GREAT help for me Actually, without that site I would NOT have switched to Tailwind due to the huge learning curve I was going to have. I still have a lot to learn about TailWind, but due to the examples I have found, their UI website, and their amazing documentation, I am doing pretty good at the moment and slowly expanding my capabilities with it.

Make a backup, upgrade, try it out, and perform a restore if you don't like it.

Activity icon

Replied to Form Request Cannot Be Sent Using POST.

This is the best explanation I could find.

-- The HTML <form> enctype Attribute is used to specify that data that will be present in form should be encoded when submitting to the server. This type of attribute can be used only if method = “POST”.

https://www.geeksforgeeks.org/html-form-enctype-attribute/

However, I use it for Get & Post. I end up with an error that killed me for 3+ days the first time.... I almost made my laptop into a frisbee figuring out how to resolve it.

Have a good one.

Sep
15
2 months ago
Activity icon

Awarded Best Reply on Form Request Cannot Be Sent Using POST.

In my view that controls the creation/edit/delete functions (I was encountering an error every time the form was submitted until I added the enctype):

<form action="{{route($ActionWanted)}}" method="GET" enctype="multipart/form-data">
.......
.......
<a href="{{ route($deleteBtn, $value->main_id )}}" [email protected]>

In the Controller for Store:

 public function store(Request $request)
    { ......  
    }

In the Controller for Update

public function update(Request $request, $id)
    {

In web.php

// \
// Area: xxx
// /
Route::get('/xxx_all', '[email protected]')->name('xxx_all');
Route::get('/xxx_edit/{edit}', '[email protected]')->name('xxx_edit');
Route::post('/xxx_edit/{edit}', '[email protected]')->name('xxx_update');
Route::get('/xxx_create', '[email protected]')->name('xxx_create');
Route::post('/xxx_create', '[email protected]')->name('xxx_store');
Route::get('/xxx_delete/{edit}', '[email protected]')->name('xxx_delete');
Route::post('/xxx_delete/{edit}', '[email protected]')->name('xxx_destroy');
Activity icon

Replied to Form Request Cannot Be Sent Using POST.

In my view that controls the creation/edit/delete functions (I was encountering an error every time the form was submitted until I added the enctype):

<form action="{{route($ActionWanted)}}" method="GET" enctype="multipart/form-data">
.......
.......
<a href="{{ route($deleteBtn, $value->main_id )}}" [email protected]>

In the Controller for Store:

 public function store(Request $request)
    { ......  
    }

In the Controller for Update

public function update(Request $request, $id)
    {

In web.php

// \
// Area: xxx
// /
Route::get('/xxx_all', '[email protected]')->name('xxx_all');
Route::get('/xxx_edit/{edit}', '[email protected]')->name('xxx_edit');
Route::post('/xxx_edit/{edit}', '[email protected]')->name('xxx_update');
Route::get('/xxx_create', '[email protected]')->name('xxx_create');
Route::post('/xxx_create', '[email protected]')->name('xxx_store');
Route::get('/xxx_delete/{edit}', '[email protected]')->name('xxx_delete');
Route::post('/xxx_delete/{edit}', '[email protected]')->name('xxx_destroy');
Sep
09
2 months ago
Activity icon

Replied to How To Insert Into Multiple Tables

The Insert statement can be changed to Eloquent, if you would like. This is just meant to give you an idea of how to go thru the form field arrays.

        $theemailid = $request->theemailid;
        if (!is_null($theemailid)) {
            $emailCount = count($theemailid);
            $theCompleteEmail = $request->theCompleteEmail;
            $thetype = $request->emailTypeID;
            for ($i = 0; $i < $emailCount; $i++) {
                    DB::insert('insert into tableNameHere (userID, connectorID, email, typeID) values (?, ?, ?, ?)',
                        [$theUserID, $id, encrypt($theCompleteEmail[$i]), $thetype[$i]]);
            }
        }
Sep
06
2 months ago
Activity icon

Replied to How To Make JS Validation?

If you want to perform the Validation on the Client Side with NO communications to the Server, you could do the following ( I do not recommend that this be used for Login/Register/Forgot-Password ).

 <form action="{{route($formAction)}}" method="POST" enctype="multipart/form-data" name="myform"
        onsubmit="return validateform()" >

And the JavaScript Validation could be something like the following:

<script>
	// \
	// This Validation is used to verify that the required fields have been entered and/or the length is
	// correct.
	// /
    function validateform(){
	// \
	// Get the values from the fields being dealt with for this form.
	// /
        var name=document.myform.accountName.value;
        var acctnbr=document.myform.AcctNbr.value;
        var bankname=document.myform.bankName.value;
        var thelen = document.myform.routingNbr.value.length;
        var thecount=0;
        var thealert="";
        var btnval = "";

	// \
	// Verify that the account name has been entered.
	// /
        if (name==null || name==""){
            thecount = thecount + 1;
            thealert = thealert.concat(thecount, ") Account's Name cannot be blank");
        }
	// \
	// Verify that the Bank Name has been entered.
	// /
        if(bankname==null || bankname==""){
            thecount = thecount + 1;
            if (thecount > 1){
                thealert = thealert.concat("<br>");
            }
            thealert = thealert.concat(thecount, ") Bank's Name cannot be blank");
        }
	// \
	// Verify that the Account # has been entered.
	// /
        if(acctnbr==null || acctnbr==""){
            thecount = thecount + 1;
            if (thecount > 1){
                thealert = thealert.concat("<br>");
            }
            thealert = thealert.concat(thecount, ") Account Number cannot be blank");
        }
	// \
	// Verify that the Routing # is 9 numbers if anything has been entered..
	// Note: 
	//	1) We do NOT need to verify if the User has entered more than 9
	// 	     digits as the field is set to accept 9 or less numbers.
	//	2) We do not need to verify if the User entered any non-number characters as
	//	     the field is set to only accept numbers.
	// /
        if(thelen > 0 && thelen < 9 ){
            thecount = thecount + 1;
            if (thecount > 1){
                thealert = thealert.concat("<br>");
            }
            thealert = thealert.concat(thecount, ") The Routing #, if any, must be 9 characters");
        }
	// \
	// Determine if 1 or more error have been found.  If 1 error that use singular, otherwise use plural.
	// /
        if (thecount > 1){
            btnval = 'Issues needing Correction';
        } else {
            btnval = 'Issue needing Correction';
        }
	// \
	// Display the errors, if any and return "FALSE" as this script failed.
	// /
        if(thecount > 0) {
            Swal.fire({
                showCloseButton: true,
                confirmButtonText: btnval,
                footer: thealert,
                confirmButtonColor: '#d33',
                backdrop: `rgba(77, 0, 0, .35)`
            });
            return false;

        }
	// \
	// No errors exist.  Nice Job!
	// Set the Password fields to be of type "Text".  This alleviates the Browser asking the User if they want to 
	// save the password.  
	// /
        if (thecount==0) {
            safeVerbalPassword.type = "text";
            unsafeVerbalPassword.type = "text";
            loginUsername.type = "text";
            loginPwd.type = "text";
        }
    }
</script>
Activity icon

Replied to User In Laravel Controllers

I use the following to verify the User is logged in. If not, they get redirected to a form informing them that they have timedout (displayed for 10 seconds) and then takes them to the login form. Also, if they aren't 18+ they get redirected to the User Profile form.

    // \
    // It is not possible to get the User's ID
    // due to this section being executed prior to middleware layer.  As such, we need to perform
    // the middleware function call.  This also resolves the issue of verifying that the User is logged in
    // each time the Controller is being executed.
    // /
    public function __construct()
    {
        $this->middleware(function ($request, $next) {
            if (!Auth::check()){
                return redirect('timeouttologin');
            } elseif (Session::get('user_age') < 18) {
                return redirect()->route('userprofile');
            }
            $this->theUserID = Auth::id();
            Session::put('CntrlArea', 'ALL_YOUR');

            return $next($request);
        });

    }

In order to save information that I am not overly keen on hitting the database or certain global variables is via either Session variables or Cache. I use Session very sparingly, only when I think I have to and only when the data is specific to a User. I use Cache for ~99% of my reference table values which helps me with maintenance and taking up the Users' resources.

Activity icon

Replied to Project Setup For Supporting Model Types That Dont Have A View In Itself?

There is no need for a separate Controller for these items. There are multiple ways to accomplish this task. Some approaches better than others. I am sure somebody will come back on my approach but what the heck... This is a long explanation....... I was informed that I needed to put 3 back tick marks before and after the code....

Let's assume that i have multiple Areas for my application and one of them is "Bank". I have multiple lookup tables which are going to be needed for the Bank such as Bank Address Type, Bank Phone Type, Bank Type, Bank Account Type.

I create a view in the database containing ALL the reference tables, but will only use the Bank specific ones in this description. I purposely created the reference tables with the same fields (id, shortDesc, fullDesc) and created a view in the db similar to the following:

CREATE OR REPLACE VIEW bankRefView AS 
    select "bankAddrType"  as theType, "bank"  as theArea, id, shortDesc, fullDesc from `ref_bankAddrTypes`
	union  
    select "bankPhoneType", "bank", id, shortDesc, fullDesc from `ref_bankPhoneTypes`
	union  
    select "bankType", "bank", id, shortDesc, fullDesc from `ref_bankTypes`
	union  
    select "bankAcctType", "bank", id, shortDesc, fullDesc from `ref_bankAcctTypes`;

I created a Controller called AllXref with one of the functions called bankXref. In my case, this Controller contains all of my Cache definitions. This allows for me to make one change and have it shared amongst ALL my Controllers:

```
   // \
  // Use Cache for the Reference data given that the data does not change often.  You
      // could use Session, but the Cache is working much better for my app.  You can change the
  // Duration to what suits you.  And you can always flush the cache with:   php artisan cache:clear
 // /
    public function bankXref(){
        return cache()->remember('all_banktypes',60*60*24*7, function(){
            return DB::table('bankRefView')
                ->select ('theType', 'id', 'shortDesc', 'fullDesc')
                ->get() ;
        });
      }

     // \
     // This will get the Cache Values
// /
    $getTheXref = new AllXref();
    $allRef = $getTheXref-> bankXref();

// \
// The following take you to the view "bankentry", returning the values contained 
// within $bankMasterValuessssss and $addrRef .  I skipped over the part where you will get
// the User's Bank values, but lets assume you put it in the variable: bankMasterValuessssss. 
// /
return view('bankentry',compact('bankMasterValuessssss','allRef'));

	Within the view You could use something like the following.  I have more code in the following 
	section to allow for making the listbox readonly, setting the class for the select, etc.  I just cut it own to 
	make it easier to read.

    <select id="bankTypeID"  name="bankTypeID"  >
           @foreach ($allRef->where('theType','=','bankType')>where('theArea','=','bank') as $category)
                    <option value="{!!$category->id!!}">
                                  {!!$category->shortDesc!!}
		</option>
           @endforeach
    </select>

As I said, there are multiple ways to accomplish what you asked help for.  This is the approach I ended up morphing to.  I am positive I will make changes over the next couple of months/years, but this is working for me at the moment.  

Have a great evening.
Aug
31
2 months ago
Activity icon

Replied to How To Make Pagination Without Parameter On URL ( Pretty URL Pagination )

Create a hidden field on the form that contains the id they are on. Retrieve the field's value, using it to determine the next form, rather than using the parameter. A possible solution....

Activity icon

Replied to @include In A @foreach Section, With A String Pass From Controller

Well, dang... I tried almost everything but that...

Thank you for the help!

And I will put the ``` before and after each code block going forward.

Activity icon

Replied to Why Should I Use Storage Directory?

It is easier for you to have the files stored in a sub-directory for maintenance and safety purposes. Otherwise, it could add a ton of files to the public directory, making it difficult to find the files you really want.

One other reason, that I found out the hard way earlier this year is: Giving Users write priv to Public allows the User to put files there, or in my case they create a sub-directory with a file that sent spam to one particular company. They then turned me in as a Spam Website, my Domain was shut off, I had to turn in a ton of documentation to prove that I was a "good" guy, and they finally turned on my domain. I lost over a week of access to the Users, was VERY stressed, and looked like an idiot...

IMHO, you may be best off creating a sub-directory where the User's files are stored.....

Two other items, while I am at it. I do NOT allow the Users to store music, executables (windows, unix, iOS, etc), or videos. Music & videos due to MPAA legal reasons, the other to alleviate legal and security issues.... Igive the file a unique name, zip and password protect the zip. The zip puts one more layer of protection between me and the Users.

Activity icon

Replied to How To Add Where Inside DB::raw() In Laravel

Here is an example of what I have done with db::raw. Note, I changed the table/field names to protect the guilty... :-)

I have used db::raw in maybe 2 queries out of ~50-60 queries. I HATE using them, it just makes the queries a bit more difficult to follow for others.

BTW, I thought I would add an example of getting a person's age, which was one of the driving reasons for me to use db::raw. I am sure there are other ways, but I knew this would do the job for me. Note, this will ONLY return the years, which is the only thing I needed to know - the Users have to be 18+ or I kick them out.

return DB::table('abcs')
            ->select('abcs.id as main_id',
                'abcs.theTitle as main_title',
                DB::raw('"IGNORE" as primary_body '),
                DB::raw('TIMESTAMPDIFF (YEAR, abcs.birthdate , CURDATE()) as main_age')
            )
            ->join('zref_toptypes', 'abcs.typeID', '=', 'zref_toptypes.id')
            ->where('abcs.userID','=', $userID)
            ->orderby("main_id","asc")
            ->get();
Activity icon

Started a new Conversation @include In A @foreach Section, With A String Pass From Controller

I want to have a foreach loop where a field's value is to be passed into an @include statement. As an example: @foreach ($theDataView->where('theType','=','dosection') as $category) @include({{$category->shortDesc}}) @endforeach

In the database table there is an entry where: shortDesc = ypi_subAreas.hideme and there is a folder in views called "ypi_subAreas" with a file called hide.blade.php

I have 8 entries for this particular loop, but it will not work even if I only have 1 entry. Suggestions greatly appreciated... Thank you.

I get the following error: syntax error, unexpected '<'