SlideShare a Scribd company logo
1 of 12
Exemplu MVC view single/all
1. Composer ->Install(dev)
2. Composer->Update(dev)
3. Install LaravelCollective
4. Modificati numele fisierului: .env.example ->.env
Vederea tuturor inregistrarilor(metoda1) cu
closure
• Pentru a crea un model vom scrie: php artisan make:model Flower
• Astfel a fost creat articolul /app/Flower.php
<?php namespace App;
use IlluminateDatabaseEloquentModel;
class Flower extends Model {
}
?>
Routes
• In fisierul /routes/web.php adaugati linia:
<?php
use AppFlower;
Route::get('flowers',function(){
$flowers=Flower::all();
return view('flowers.show')->with('flowers', $flowers);
});
?>
Astfel vor fi extrase toate inregistrarile din db si vor fi incarcate in
variabila $flowers, care va fi trimisa vederii.
Vederea /resources/views/flowers/show.blade.php
<!DOCTYPE html>
<html>
<head><title>Flowers</title></head>
<h1>Flowers data</h1>
<table>
<tr>
<th>Nume</th>
<th>Marime</th>
<th>Culoare</th>
<th>Pret</th>
</tr>
@foreach($flowers as $flower)
<tr>
<td><?php echo link_to("/flowers/{$flower->nume}", $flower->nume);?></td>
<td><?php echo $flower->culoare;?></td>
<td><?php echo $flower->marime;?></td>
<td><?php echo $flower->pret;?></td>
</tr>
@endforeach
</table>
</html>
• Vizualizati http://localhost/laravelproj/public/flowers
Vederea unei inregistrari
particulare(metoda1)- cu closer
• Editati fisierul /routes/web.php astfel:
<?php
use AppFlower;
Route:get('flowers',function(){
$flowers=Flower::all();
return view('flowers.show')->with('flowers', $flowers);
});
Route::get('flowers/{nume}', function($nume){
//select * from flowers where flower=$flower LIMIT 1
$flower=Flower::where('nume','=',$nume)->first();
return view('flowers.showflower', ['flower'=>$flower]);
});
?>
Vederea unei inregistrari
Vederea /resources/views/flowers/showflower.blade.php
<!DOCTYPE html>
<html>
<head><title>Flowers</title></head>
<body>
<h1>Details for: <?php echo $flower->nume;?></h1>
<h3>Culoare: <?php echo $flower->culoare;?></h3>
<h3>Marime: <?php echo $flower->marime;?></h3>
<h3>Pret: <?php echo $flower->pret;?></h3>
<a href='http://localhost/laravelproj/public/flowers'>Back</a>
</body>
</html>
METODA2 – acelasi lucru cu controllere in
routes(fara closure)!!!
• Acelasi lucru se poate obtine si fara closure, scriind codul functiilor
closure (functiile din fisierul routes) direct in functiile din
FlowersController, astfel:
• Editati fisierul /routes/web.php astfel:
<?php
use AppFlower;
Route::get('flowers', 'FlowersController@index');
Route::get('flowers/{nume}', 'FlowersController@show');
?>
• Creati controller-ul /app/Http/Controllers/FlowersController.php
care va contine codul functiilor closure (functiile din fisierul routes) in functiile sale index si show:
<?php namespace AppHttpControllers;
use AppHttpRequests;
use AppHttpControllersController;
use IlluminateHttpRequest;
//adaugati linia urmatoare
use AppFlower;
class FlowersController extends Controller {
public function index()
{
$flowers=Flower::all();
return view('flowers.show')->with('flowers', $flowers);
}
public function show($nume)
{
//select * from flowers where flower=$flower LIMIT 1
$flower=Flower::where('nume','=',$nume)->first();
return view('flowers.showflower', ['flower'=>$flower]);
}?>
Pentru a vizualiza in browser, se folosesc vederile definite anterior.
• Pentru a verifica daca sunt inregistrari in baza de date, inainte de a afisa datele, vom modifica vederea /resources/views/flowers/show.blade.php astfel:
<!DOCTYPE html>
<html>
<head><title>Flowers</title></head>
<h1>Flowers data</h1>
@if (count($flowers)==0)
Nu sunt inregistrari in db!
@else
<table>
<tr>
<th>Nume</th>
<th>Marime</th>
<th>Culoare</th>
<th>Pret</th>
</tr>
@foreach($flowers as $flower)
<tr>
<td><?php echo link_to("/flowers/{$flower->nume}", $flower->nume);?></td>
<td><?php echo $flower->culoare;?></td>
<td><?php echo $flower->marime;?></td>
<td><?php echo $flower->pret;?></td>
</tr>
@endforeach
</table>
@endif
</html>

More Related Content

What's hot

Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel PassportMichael Peacock
 
Using HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless IntegrationUsing HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless IntegrationCiaranMcNulty
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialKaty Slemon
 
devise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwandevise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwanTse-Ching Ho
 
More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weiboshaokun
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroChristopher Pecoraro
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发shaokun
 
Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertKaty Slemon
 
Rails3ハンズオン資料
Rails3ハンズオン資料Rails3ハンズオン資料
Rails3ハンズオン資料Shinsaku Chikura
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationAbdul Malik Ikhsan
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In DepthKirk Bushell
 
Simple restfull app_s
Simple restfull app_sSimple restfull app_s
Simple restfull app_snetwix
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Sumy PHP User Grpoup
 

What's hot (20)

Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 
Using HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless IntegrationUsing HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless Integration
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorial
 
devise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwandevise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwan
 
Elefrant [ng-Poznan]
Elefrant [ng-Poznan]Elefrant [ng-Poznan]
Elefrant [ng-Poznan]
 
More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weibo
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
Phinx talk
Phinx talkPhinx talk
Phinx talk
 
Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expert
 
Rails3ハンズオン資料
Rails3ハンズオン資料Rails3ハンズオン資料
Rails3ハンズオン資料
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
 
Laravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php frameworkLaravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php framework
 
Pundit
PunditPundit
Pundit
 
Simple restfull app_s
Simple restfull app_sSimple restfull app_s
Simple restfull app_s
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 

Similar to MVC view single/all

16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravelRazvan Raducanu, PhD
 
Introduction to nu soap
Introduction to nu soapIntroduction to nu soap
Introduction to nu soapvikash_pri14
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuLucas Renan
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleKaty Slemon
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - IntroductionVagmi Mudumbai
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails Hung Wu Lo
 
Synapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindiaComplaints
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsDeepak Chandani
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 
Frameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPFrameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPDan Jesus
 

Similar to MVC view single/all (20)

9. Radio1 in Laravel
9. Radio1 in Laravel 9. Radio1 in Laravel
9. Radio1 in Laravel
 
16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravel
 
Introduction to nu soap
Introduction to nu soapIntroduction to nu soap
Introduction to nu soap
 
18.register login
18.register login18.register login
18.register login
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
4. copy2 in Laravel
4. copy2 in Laravel4. copy2 in Laravel
4. copy2 in Laravel
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails
 
Synapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephp
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Frameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPFrameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHP
 

More from Razvan Raducanu, PhD (20)

12. edit record
12. edit record12. edit record
12. edit record
 
11. delete record
11. delete record11. delete record
11. delete record
 
10. view one record
10. view one record10. view one record
10. view one record
 
9. add new record
9. add new record9. add new record
9. add new record
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
7. copy1
7. copy17. copy1
7. copy1
 
6. hello popescu 2
6. hello popescu 26. hello popescu 2
6. hello popescu 2
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 
4. forme in zend framework 3
4. forme in zend framework 34. forme in zend framework 3
4. forme in zend framework 3
 
3. trimiterea datelor la vederi
3. trimiterea datelor la vederi3. trimiterea datelor la vederi
3. trimiterea datelor la vederi
 
2.routing in zend framework 3
2.routing in zend framework 32.routing in zend framework 3
2.routing in zend framework 3
 
1. zend framework intro
1. zend framework intro1. zend framework intro
1. zend framework intro
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
17. delete data
17. delete data17. delete data
17. delete data
 
16. edit data
16. edit data16. edit data
16. edit data
 
15. view single data
15. view single data15. view single data
15. view single data
 
14. add data in symfony4
14. add data in symfony4 14. add data in symfony4
14. add data in symfony4
 
13. view data
13. view data13. view data
13. view data
 
12.doctrine view data
12.doctrine view data12.doctrine view data
12.doctrine view data
 
11. move in Symfony 4
11. move in Symfony 411. move in Symfony 4
11. move in Symfony 4
 

Recently uploaded

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

MVC view single/all

  • 1. Exemplu MVC view single/all
  • 2.
  • 3. 1. Composer ->Install(dev) 2. Composer->Update(dev) 3. Install LaravelCollective 4. Modificati numele fisierului: .env.example ->.env
  • 4. Vederea tuturor inregistrarilor(metoda1) cu closure • Pentru a crea un model vom scrie: php artisan make:model Flower • Astfel a fost creat articolul /app/Flower.php <?php namespace App; use IlluminateDatabaseEloquentModel; class Flower extends Model { } ?>
  • 5. Routes • In fisierul /routes/web.php adaugati linia: <?php use AppFlower; Route::get('flowers',function(){ $flowers=Flower::all(); return view('flowers.show')->with('flowers', $flowers); }); ?> Astfel vor fi extrase toate inregistrarile din db si vor fi incarcate in variabila $flowers, care va fi trimisa vederii.
  • 6. Vederea /resources/views/flowers/show.blade.php <!DOCTYPE html> <html> <head><title>Flowers</title></head> <h1>Flowers data</h1> <table> <tr> <th>Nume</th> <th>Marime</th> <th>Culoare</th> <th>Pret</th> </tr> @foreach($flowers as $flower) <tr> <td><?php echo link_to("/flowers/{$flower->nume}", $flower->nume);?></td> <td><?php echo $flower->culoare;?></td> <td><?php echo $flower->marime;?></td> <td><?php echo $flower->pret;?></td> </tr> @endforeach </table> </html>
  • 8. Vederea unei inregistrari particulare(metoda1)- cu closer • Editati fisierul /routes/web.php astfel: <?php use AppFlower; Route:get('flowers',function(){ $flowers=Flower::all(); return view('flowers.show')->with('flowers', $flowers); }); Route::get('flowers/{nume}', function($nume){ //select * from flowers where flower=$flower LIMIT 1 $flower=Flower::where('nume','=',$nume)->first(); return view('flowers.showflower', ['flower'=>$flower]); }); ?>
  • 9. Vederea unei inregistrari Vederea /resources/views/flowers/showflower.blade.php <!DOCTYPE html> <html> <head><title>Flowers</title></head> <body> <h1>Details for: <?php echo $flower->nume;?></h1> <h3>Culoare: <?php echo $flower->culoare;?></h3> <h3>Marime: <?php echo $flower->marime;?></h3> <h3>Pret: <?php echo $flower->pret;?></h3> <a href='http://localhost/laravelproj/public/flowers'>Back</a> </body> </html>
  • 10. METODA2 – acelasi lucru cu controllere in routes(fara closure)!!! • Acelasi lucru se poate obtine si fara closure, scriind codul functiilor closure (functiile din fisierul routes) direct in functiile din FlowersController, astfel: • Editati fisierul /routes/web.php astfel: <?php use AppFlower; Route::get('flowers', 'FlowersController@index'); Route::get('flowers/{nume}', 'FlowersController@show'); ?>
  • 11. • Creati controller-ul /app/Http/Controllers/FlowersController.php care va contine codul functiilor closure (functiile din fisierul routes) in functiile sale index si show: <?php namespace AppHttpControllers; use AppHttpRequests; use AppHttpControllersController; use IlluminateHttpRequest; //adaugati linia urmatoare use AppFlower; class FlowersController extends Controller { public function index() { $flowers=Flower::all(); return view('flowers.show')->with('flowers', $flowers); } public function show($nume) { //select * from flowers where flower=$flower LIMIT 1 $flower=Flower::where('nume','=',$nume)->first(); return view('flowers.showflower', ['flower'=>$flower]); }?> Pentru a vizualiza in browser, se folosesc vederile definite anterior.
  • 12. • Pentru a verifica daca sunt inregistrari in baza de date, inainte de a afisa datele, vom modifica vederea /resources/views/flowers/show.blade.php astfel: <!DOCTYPE html> <html> <head><title>Flowers</title></head> <h1>Flowers data</h1> @if (count($flowers)==0) Nu sunt inregistrari in db! @else <table> <tr> <th>Nume</th> <th>Marime</th> <th>Culoare</th> <th>Pret</th> </tr> @foreach($flowers as $flower) <tr> <td><?php echo link_to("/flowers/{$flower->nume}", $flower->nume);?></td> <td><?php echo $flower->culoare;?></td> <td><?php echo $flower->marime;?></td> <td><?php echo $flower->pret;?></td> </tr> @endforeach </table> @endif </html>