1,490 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
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.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Tray2 left a reply on What Service Do You Use For Your Application And Website Hosting?
I'm using one.com and are quite happy with their prices and uptime. However they don't allow me to change the document riit so I have to rely on .htaccess to get it to point to the public folder and they don't allow phar so I can't use composer.
Tray2 left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel
I'm glad you solved it :)
Tray2 left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel
There is obviously something fishy in you SQL. Why not try something simple and get that to work first?
INSERT INTO temp (object_type, object_id)
SELECT cg.object_type, cg.object_id
FROM hrp1001_cg cg;
If you get that to work you should be able to add a more complex query.
Otherwise you can try creating a procedure in the database and call it in a raw query. Something like
DB::raw('EXECUTE my_sweet_procedure');
Tray2 left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel
Do you really need to put it in a temp table? Can't you just create a view and query that?
Tray2 left a reply on Php Artisan Migrate - Unknown Database Error - Laravel 5.7 From Scratch
You are welcome and please mark the thread as solved. You do this by marking my previous answer as "best reply"
Tray2 left a reply on Php Artisan Migrate - Unknown Database Error - Laravel 5.7 From Scratch
Login to your mysql server and create the database with the following command
create database tutorial;
Tray2 left a reply on Forge Server Connect SQL Remotely
I would not disable any of the security measurs that is in place.
Not entierly sure what you are trying to do with "checking values" but I would create an API that I can use to retrieve the desired information.
Tray2 left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel
Try using DB::insert
instead of DB::raw
.
https://laracasts.com/discuss/channels/laravel/raw-insert-query
Tray2 left a reply on Fetch Data From Multiple Tables
Can you provide some example data from your tables and the desired result?
Tray2 left a reply on How To Implement Oracle Query To Select From Different Tables In Laravel
Yes it is possible to run it in DB:raw, just add DB:raw("your query here");
and is should work.
I would suggest either giving you tables better names or at least aliases to make the query more readable.
Tray2 left a reply on Laravel 5.4: Insert Each Item As Row From One Form
Something like
foreach ($request->products as $product) {
Model::create(['product_id' => $product]);
}
Tray2 left a reply on How To Access Functions Within A Model, In A View
Depends on what you are trying to do. If you are trying to convert data returned from the database then you can have it in your model.
Tray2 left a reply on Unit Converter For Product
I would probably calculate it on the fly instead.
Something like this
id | product_id |box_qty | carton_qty
SELECT 2 * box_qty / carton_qty as cartons
FROM packings
WHERE product_id = 1
Tray2 left a reply on 'php' Is Not Recognized As An Internal
Either PHP is not installed or not in the path.
Tray2 left a reply on How To Access Functions Within A Model, In A View
{{ $model->pressure() }}
Should work if you send the model collection to the view.
Tray2 left a reply on Table Structure For A Different Kind Of EWallet System
I would probably go with something like this.
id, transaction_type, customer_id, wallet_id, amount
That way a customer can have more than one wallet.
Tray2 left a reply on Render Two Tables In One Loop
I haven't tried to do it that way, I usually use plain SQL to load everything I need when doing more "complex" queries like that one.
I'm sure it's possible to fix but I don't know how.
Not knowing what your table structure is I would try doing something like this
SELECT t1.field1, t1field2, t2.field1, t2.field2
FROM table1 t1,
table2 t2
WHERE t1.table2_id = t2.id
UNION ALL
SELECT t3.field1, t1field3, t4.field1, t4.field2
FROM table3 t3,
table3 t4
WHERE t3.table4_id = t4.id
That way you can load all your tables into one collection.
And if it gets messy you can use a database view
CREATE VIEW all_posts AS
SELECT t1.field1, t1field2, t2.field1, t2.field2
FROM table1 t1,
table2 t2
WHERE t1.table2_id = t2.id
UNION ALL
SELECT t3.field1, t1field3, t4.field1, t4.field2
FROM table3 t3,
table3 t4
WHERE t3.table4_id = t4.id
And then you can create a model for it and use some nice eloquent.
$posts = AllPost::latest()->take(5)->get():
Tray2 left a reply on Render Two Tables In One Loop
You don't have to add them to the table just add it like I did in my last post as hardcoded values,
Tray2 left a reply on Render Two Tables In One Loop
You don't have to have exactly the same names you can use aliases for that.
select id post_id, photografer copyright_owner, 'gallery' type from galleries
unioin all
select id post_id , director copyright_owner, 'video' type from videos
They need to be in the same format and the same amount of fields from both tables.
Tray2 left a reply on Trying To Load Selected Value On Select
Something along the lines of this should work
v-if (product.id === selectedProductId) selected="selected"
Tray2 left a reply on Method 'table' Not Found In \Illuminate\Support\Facades\DB
If that solved the issue plaese mark the thread as solved.
Tray2 left a reply on Method 'table' Not Found In \Illuminate\Support\Facades\DB
If you use the $users
variable in your index view you either need to pass it or check if it set in your view.
@if(isset($users))
@foreach($users as $user)
//code
@endforeach
@endif
Tray2 left a reply on Check User Has Row
$rowCount = Model::where('user_id', $user->id)->count();
if ($rowCount > 0) {
return true;
}
return false;
Or something similar.
Tray2 left a reply on Render Two Tables In One Loop
I would do something like this.
$posts = DB::raw('SELECT * FROM (SELECT * FROM videos UNION ALL SELECT * FROM galleries) ORDER BY created_at DESC');
That way you get the records from both tables at one and in the correct order. You need to have the same fields from both tables and you need do have a hardcoded fields to me able to link to the correct id.
You can probably do this in Eloquent too.
You could do a database view that you can query with some nice eloquent as another option. http://www.mysqltutorial.org/create-sql-views-mysql.aspx
Tray2 left a reply on Best Way To Handle Huge Insertion In Laravel Considering Both Timeout And Memory Issue
I would probably go and use the csv as an external table and then loop through it.
https://mariadb.com/kb/en/library/connect-external-table-types/
If this is a one time thing I'd just import it in some db-editor.
Tray2 left a reply on Class DistributorController Doesr Not Exist
Why make it more complex then necessary? Always go with KISS.
Tray2 left a reply on Class DistributorController Doesr Not Exist
Try changing
Route::get('/index','[email protected]')->name('index')
To
Route::get('/index','[email protected]')->name('index');
Tray2 left a reply on Math Operations On Query
Read this one out loud
for ($i=0; $i < 0; $i++)
For $i
is equal to zero and while $i
is less then zero then inrement $i
by one.
If it even runs it does it one time and one time only.
Not knowing where you more about your code, I would suggest you create an API controller to handle this and use ajax to hit the endpoint to change this number,
Also I small reminder never update anything in the database with a GET
request.
Tray2 left a reply on Permissions On Linux Ubuntu
Try sudo chmod 755 /usr/local/bin/composer
and then run it again.
Tray2 left a reply on .htaccess Vs _htaccess ?
If you are using Apache then you should have an .htaccess file. I have never heard of a _htaccess.
Tray2 left a reply on How Can I Get 3 Table Data In Index In Laravel?
I would probably use a database view for this.
CREATE VIEW school_views AS
SELECT s.name,
s.phone,
sd.image,
r.rating_vakue,
r.status
FROM schools s,
school_details sd,
ratings r
WHERE s.id = sd.school_id
AND s.id = r.school_id
Then I'd create an Model for it and then in the controller I do
$schools = SchoolView::all();
return view('schools.index', compact('schools'));
That way I don't need to create any complicated eloquent query. Put the view creation in a migration file.
In yourup()
DB::statement("CREATE VIEW school_views AS
SELECT s.name,
s.phone,
sd.image,
r.rating_vakue,
r.status
FROM schools s,
school_details sd,
ratings r
WHERE s.id = sd.school_id
AND s.id = r.school_id");
and in your down()
DB::statement('DROP VIEW school_views');
However in your case I'd put all the fields in one table since they are one to one relationships. I'm not saying you always should put one to one in the same table but in this case I would at least for starters.
Tray2 left a reply on Calculation In Controller
I would do something along the lines of this
SELECT
(SELECT count(*) FROM employees WHERE primary_position = 5 AND status = 5) medic_count,
(SELECT count(*) FROM employees WHERE primary_position = 4 AND status = 8) aemt_count ,
etc
Tray2 left a reply on Dynamic Routes In Laravel
I meant what does the link look like?
https://somedomain.dev/somemodel/something?page=1
Tray2 left a reply on Dynamic Routes In Laravel
What does it look like in the browser?
I don't use query strings in my controllers if I can help it.
However if it's a query string then it's a key value pair and you use the request->query('key')
to get the value.
Tray2 left a reply on Checkout Form Isn't Submitting
That is because you don't send any cart values from you form. This is what you have in your code.
<form method="post" action="{{ url('/checkout') }}" class="needs-validation" novalidate>
{{csrf_field() }}
<input type="text" name="name" class="form-control" id="firstName"
placeholder="name" value="" required
style="border: 1px solid black !important;">
<input type="email" name="email" class="form-control" id="email"
placeholder="[email protected]"
required="required" style="border: 1px solid black !important;">
<input type="text" name="address" class="form-control" id="address" placeholder="1234
Main St" required
style="border: 1px solid black !important;">
<select name="country" class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option value="usa">United States</option>
</select>
<select name="state" class="custom-select d-block w-100" id="state" required>
<option value="">Choose...</option>
<option value="cal">California</option>
</select>
<select name="city" class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option value="lhr">United States</option>
</select>
<input type="text" name="zipcode" class="form-control" id="zip" placeholder="" required
style="border: 1px solid black !important;">
<input type="text" name="mobile" class="form-control" id="zip" placeholder="" required
style="border: 1px solid black !important;">
<button class="btn btn-primary btn-lg btn-block" type="submit" style="background-color:
black;">Place Order</button>
</form>
You need to add a field or more depending on your solution with the cart. Either you pass a JSON string with all the items and quantities or a reference to a cart_id in some table.
Tray2 left a reply on Dynamic Routes In Laravel
You can handle the query string in your controller via the Request.
Something like
$pageData = Model::all();
if($request->query('component') == 'page-simpleheader) {
return view('pages.simpleheader', compact(pageData);
} else {
return view('pages.someotherpage', compact('pageData');
}
Tray2 left a reply on Checkout Form Isn't Submitting
You are not passing the product_id from your form.
All the fields in the table that is not nullable and don't have a default value must be passed in from your form to the request.
Do a
dd($request);
in your controller. There you will see what is passed and you can compare it to your table.
I suggest you stopp trying to do stuff until you learned more of the basics of html forms, php and mysql.
Tray2 left a reply on Check If User Comment Added 24h Ago, If Yes Then Add New Comment
Sure you can.
Tray2 left a reply on Checkout Form Isn't Submitting
What does your migration look like?
and desc <table>
Tray2 left a reply on Check If User Comment Added 24h Ago, If Yes Then Add New Comment
Something like
$com = $Comment::where('user_id', Auth::id())->where('created_at', '>', sysdate - 24)->count();
if ($com >= 1) {
//Comeback in 24h
} else {
//Go ahead comment
}
Should do the trick. 8Not sure about the date but there is probably a nifty Carbon method to solve that.
Tray2 left a reply on Checkout Form Isn't Submitting
Probably cause your id column doesn't auto increment.
Tray2 left a reply on Checkout Form Isn't Submitting
The last error you can solve by adding use App\Order;
in yor controller.
Tray2 started a new conversation Two Different Classes For Adding And Removing Records In A Pivot Table?
I have a delicate little issue. It's not really a problem but rather a question about preferences.
I'm building an app that allows people to add books to it and have their collection listed. Something like Discogs only smaller scale and for books.
So when I list the books in the database ther is an option to add it to your collection and
$book->addToCollection();
Seems like an easy way to do it. Then I have a BookUsers to keep track of the collection. Now I need to be able to remove a book from my collection thus giving me the following path choices.
$book->removeFromCollection
$bookUser->removeFromCollection
addToCollection
from Book and place them both in BookUser.I'm ok with all three of them but what is your take on this?
Tray2 left a reply on How To Delete Duplicates From Database?
No, It's something in the syntaxthat it sqwuaks about. Try changing the 'x' to 1 and run it again.
Also see this link for more info on exists http://www.mysqltutorial.org/mysql-exists/
Tray2 left a reply on How To Delete Duplicates From Database?
Something like this should work for you.
DELETE t1
FROM questions t1
INNER JOIN
questions t2
WHERE t1.id < t2.id
AND t1.description = t2.description
AND t1.source = t2.source
AND t1.image = t2.image
AND t1.choice exists IN (SELECT 'x' FROM choices c WHERE c.choice = t1.choice );
Tray2 left a reply on DB Schema: Multiple Choice And Fill In The Blank Q & A
I would say it depends on how many questions you are going to have.
If you have 1000 and 3 answers for each then I might add the question_id to the answer_users table otherwise it's a bit more complex to see what the user answered to a specific question.
Tray2 left a reply on How To Keep Old Model's Data Until New Changes Are Approved ??
A section is submitted and awaiting approval.
The admin aproves the change and the section is marked as approved.
A update of previous section is submitted into a new not approved record.
The admin then approves the section and it's marked as approved.
The page displays the lates approved version (version 2) version 1 is still in the table but is filtered out since it's not the latest version.
A third submission of the section is made and awaits approvel.
The admin decides not to approve the section thus not marking it as approved.
The page still shows version 2.
The rejected section is updated (this should be possible with not approved sections).
The admin then approves the updated version 3
The page displays version 3.
Think of it as a version handling system.
Tray2 left a reply on How To Keep Old Model's Data Until New Changes Are Approved ??
I would make it simple and add another column to the table like "approved" then I would get the latest record that is approved and as soon as any new record is approved it will be the latest. I would not delete the old records unless they grow in number very rapidly.
Tray2 left a reply on Two Post Forms In | Route Problem
Both your POST routes are the same so the first one will always be chosen.
Change the forst route to something like.
Route::post('business/video', '[email protected]')->middleware('auth');
I would create seperate route and controller for the media and not garble the BusinessController with lots of methods.
Think, index, show, store, update, create, delete/destroy. That way you can later on switch to route resource.
Tray2 left a reply on Phpunit Class Env Does Not Exist?
That worked :) Thank you so much.
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.
............................................................... 63 / 127 ( 49%)
............................................................... 126 / 127 ( 99%)
. 127 / 127 (100%)
Time: 12.03 seconds, Memory: 32.00MB
OK (127 tests, 367 assertions)