laravel Parse error on view - php

I'm getting Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ')' on my view file. This is my controller:
public function gclogs()
{
$gclogs = DB::table('duplicategcs')->orderBy('created_at', 'desc')->paginate(20);
return view('admin.gclogs')->with('gclogs',$gclogs);
}
and this is just a snippet from view:
#foreach($gclogs as $gclog)
<tr>
<td>
{{gclog->id}}
</td>
<td>
{{gclog->user_id}}
</td>
<td>
{{gclog->google_id}}
</td>
<td>
{{gclog->google_email}}
</td>
<td>
{{gclog->created_at}}
</td>
<td>
User Edit
</td>
</tr>
#endforeach
</tbody>
</table>
<div align="center">
{{ $gclogs->render() }}
</div>

You forget use $ inside foreach.
Try this:
#foreach($gclogs as $gclog)
<tr>
<td>
{{$gclog->id}}
</td>
<td>
{{$gclog->user_id}}
</td>
<td>
{{$gclog->google_id}}
</td>
<td>
{{$gclog->google_email}}
</td>
<td>
{{$gclog->created_at}}
</td>
<td>
User Edit
</td>
</tr>
#endforeach
</tbody>
</table>
<div align="center">
{{ $gclogs->render() }}
</div>

Related

Laravel: How to show form after submission?

I am new to Laravel and currently working on a project where the guests enter form data for booking a room in a hotel and after submitting it, they will be redirected to a page showing their booking they have just done. I know this can be done by allowing guests to create login account but my project requires login only for the backend(admin). (Q2.)Also the guests can view booking by entering the booking ID and their last name.
My controller:
public function store(Request $request)
{
$book = new book();
$book->title = $request->input('title');
$book->fname = $request->input('firstname');
$book->lname = $request->input('lastname');
$book->country = $request->input('country');
$book->phone = $request->input('phone');
$book->email = $request->input('email');
$book->no_rooms = $request->input('no_rooms');
$book->room_type_id = $request->input('type_room');
$book->no_adults = $request->input('adults');
$book->no_children = $request->input('children');
$book->meal_id = $request->input('meal');
$book->check_in = $request->input('check_in');
$book->check_out = $request->input('check_out');
$book->save();
}
public function show(book $book)
{
return view('book.show', compact('book'));
}
The way I want it to display after it has been submitted:
<div class="row">
<div class="col-6">
<table class="table table-striped text-dark">
<tbody>
<tr>
<td> Name: </td>
<td> {{$book->title}} {{$book->firstname}} {{$book->lastname}} </td>
</tr>
<tr>
<td> Phone </td>
<td> {{$book->phone}} </td>
</tr>
<tr>
<td> Email </td>
<td> {{$book->email}} </td>
</tr>
<tr>
<td> Phone </td>
<td> {{$book->phone}} </td>
</tr>
<tr>
<td> Passport Issued: </td>
<td> {{$book->country}} </td>
</tr>
<tr>
<td> Number of rooms: </td>
<td> {{$book->no_rooms}} </td>
</tr>
<tr>
<td> Room Type </td>
<td> {{$book->type_room}} </td>
</tr>
<tr>
<td> No of adults: </td>
<td> {{$book->adults}} </td>
</tr><tr>
<td> No of children: </td>
<td> {{$book->children}} </td>
</tr>
<tr>
<td> Meal plan: </td>
<td> {{$book->meals_id}} </td>
</tr>
<tr>
<td> Check-in: </td>
<td> {{$book->check_in}} </td>
</tr>
<tr>
<td> Check-out: </td>
<td> {{$book->check_out}} </td>
</tr>
</tbody>
</table>
</div>
</div>
You can redirect to the show method from the bottom of your store method:
// Replace MyController with the name of your controller
return redirect()->action(
'MyController#show', ['book' => $book]
);
For more information check out the documentation: https://laravel.com/docs/master/redirects#redirecting-controller-actions
If I understand correctly your situation, you wish to show the same data introduced by the user after form submission.
I can think that redirecting to a page that show your div without anything else, is not enough. You'll still need to access to data entered in the form.
Laravel store form data in a session variable called old, according to documentation, that variable should be available during next request after submission, so you could try to get data using
<table class="table table-striped text-dark">
<tbody>
<tr>
<td> Name: </td>
<td> {{ old('title') }} {{ old('firstname') }} {{ old('lastname') }} </td>
</tr>
<tr>
<td> Phone </td>
<td> {{ old('phone') }} </td>
</tr>
<tr>
<td> Email </td>
<td> {{ old('email') }} </td>
</tr>
<tr>
<td> Phone </td>
<td> {{ old('phone') }} </td>
</tr>
<tr>
<td> Passport Issued: </td>
<td> {{ old('country') }} </td>
</tr>
<tr>
<td> Number of rooms: </td>
<td> {{ old('no_rooms') }} </td>
</tr>
<tr>
<td> Room Type </td>
<td> {{ old('type_room') }} </td>
</tr>
<tr>
<td> No of adults: </td>
<td> {{ old('adults') }} </td>
</tr><tr>
<td> No of children: </td>
<td> {{ old('children') }} </td>
</tr>
<tr>
<td> Meal plan: </td>
<td> {{ old('meals_id') }} </td>
</tr>
<tr>
<td> Check-in: </td>
<td> {{ old('check_in') }} </td>
</tr>
<tr>
<td> Check-out: </td>
<td> {{ old('check_out') }} </td>
</tr>
</tbody>
</table>
Just in case that you don't have old data available in your session because a successive redirect, you should inject that data in your session using flash.
You can find more detailed information here, in laravel documentation
You can just use the laravel helper redirect()
return redirect()->route('route name here');
or
return redirect('your-form-path');
read more here: laravel http redirects

My Images getting smaller in next page - DOMPDF

Here's the first page
Here's the second page, the image is getting smaller
Created with DOMPDF and Laravel, the first page, my image is fine, but when the second page is getting smaller, i don't know why.. i've been trying to use div, but its still not working
i'm using table and here's my code
<table>
<tbody>
<tr>
<td>
<img src="{{$content['image2']}}" class="img kecil" />
</td>
<td>
{!! $content['paragraph2'] !!}
</td>
</tr>
<tr>
<td>
<img src="{{$content['image2']}}" class="img kecil" />
</td>
<td>
{!! $content['paragraph2'] !!}
</td>
</tr>
<tr>
<td>
<img src="{{$content['image2']}}" class="img kecil" />
</td>
<td>
{!! $content['paragraph2'] !!}
</td>
</tr>
<tr>
<td>
<img src="{{$content['image2']}}" class="img kecil" />
</td>
<td>
{!! $content['paragraph2'] !!}
</td>
</tr>
<tr>
<td>
<img src="{{$content['image2']}}" class="img kecil" />
</td>
<td>
{!! $content['paragraph2'] !!}
</td>
</tr>
<tr>
<td>
<img src="{{$content['image2']}}" class="img kecil" />
</td>
<td>
{!! $content['paragraph2'] !!}
</td>
</tr>
</tbody>
</table>
I also using bootstrap, what should i do to fix this? Thanks

PHP RAND and fuzzy logic rules

Well, let's say I have variable a, b and c:
a = R R R
b = S S S
c = T T T
number = 1 to 3;
In my case I need to display the 27 row of total (var * var * var), but the result need to be like this and generate random number between 1 to 3:
<table>
<tr>
<td> R </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> S </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> T </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> T </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> S </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> T </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> T </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> S </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> T </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> T </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> R </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> S </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> T </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> S </td>
<td> T </td>
<td> T </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> R </td>
<td> R </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> R </td>
<td> S </td>
<td> number </td>
</tr>
<tr>
<td> T </td>
<td> S </td>
<td> T </td>
<td> number </td>
</tr>
</table>
How can I achieve this result in php?
Any help will be very much appreciated.
Thanks.
Here you go:
$a = ['R','R','R'];
$b = ['S','S','S'];
$c = ['T','T','T'];
$array = [$a, $b, $c];
<table>
for($i=0 ; i<27; i++) {
<tr>
<td> echo $array[rand(0,2)][rand(0,2)] ; </td>
<td> echo $array[rand(0,2)][rand(0,2)] ; </td>
<td> echo $array[rand(0,2)][rand(0,2)] ; </td>
<td> echo rand(0,2)</td>
</tr>
}
</table>
// !! you need to concat php with HTML !!

Session Variable With Array

i want to use session variable in the code. my requirement is that when i click on "edit/Delete" button,record against the correspondence row is deleted automatically. can any one plz help me how to resolve this problem and also tell me how to use session variable.
`<?php
while($row = $result->fetch_array())
print("
<tr>
<td> $row[0] </td>
<td> $row[1] </td>
<td> $row[2] </td>
<td> $row[3] </td>
<td> $row[4] </td>
<td> <a href='dscm-Emp-Modification.php?ID= $row[0]'>Edit</a></td>
<td> <a href='dscm-Emp-Delete.php?DID= $row[0]'>Delete</a></td>
</tr>
");
?>`
i tried following codes but neither of them worked for me:
//method 1
while($row = $result->fetch_array())
$_SESSION['a']=$row[0];
$_SESSION['b']=$row[1];
$_SESSION['c']=$row[2];
$_SESSION['d']=$row[3];
$_SESSION['e']=$row[4];
print("
<tr>
<td> $_SESSION[a] </td>
<td> $_SESSION[b] </td>
<td> $_SESSION[c] </td>
<td> $_SESSION[d]</td>
<td> $_SESSION[e]</td>
<td> <a href='dscm-Emp-Modification.php?ID= $row[0]'>Edit</a></td>
<td> <a href='dscm-Emp-Delete.php?DID= $row[0]'>Delete</a></td>
</tr>
");
//method 2
{
for ($a=0; $a<=4; $a++){
$_SESSION['data']=$row;
print("
<tr>
<td> $_SESSION[data] </td>
<td> $_SESSION[data] </td>
<td> $_SESSION[data] </td>
<td> $_SESSION[data] </td>
<td> $_SESSION[data] </td>
<td> <a href='dscm-Emp-Modification.php?ID= $row[0]'>Edit</a></td>
<td> <a href='dscm-Emp-Delete.php?DID= $row[0]'>Delete</a></td>
</tr>
");
}
}
You need to call the session_start() function befor use the $_SESSION-Array.
Please read more about sessions in the PHP documentation here.

How do I make a Dynamic table that structures itself with what I have in the database?

I am trying to make it so that when I get the Units from the database if they are the same unit to combine the cells and after the end of the combination of the cells one cell under and two cell to the right to do an increment (UI, UII, UIII, UIV, UV) cell.
My database:
Name: gradebook
Table name: Evidence
IdEvidence (int)(auto Increment)
id_class (int)(fk)
evaluation (varchar)
unit (varchar)
percentage (int)
dueDate (date)
this is the code I have so far:
<?php
mysql_connect('localhost','root','root');
mysql_select_db('Evidence');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<table width="200" border="1">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>Unit1</td>
<td>Unit1</td>
<td> </td>
<td> </td>
<td>Unit2</td>
<td> </td>
<td> </td>
<td>Unit3</td>
<td>Unit3</td>
<td> </td>
<td> </td>
<td>Unit4</td>
<td>Unit4</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Name</td>
<td> </td>
<td>EDi</td>
<td>ED1</td>
<td>EC1</td>
<td>P</td>
<td>UI</td>
<td>EP1</td>
<td>P</td>
<td>UII</td>
<td>EC2</td>
<td>EP2</td>
<td>P</td>
<td>UIII</td>
<td>EP3</td>
<td>ED2</td>
<td>P</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Due Date</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>

Categories