php class NumberController extends BaseController public function sear

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class NumberController extends BaseController {
public function search() {
if (!($_GET)){
return View::make('numbers.search');
} else {
$num = Number::trimNumber($_GET['number']);
if ($num == '') {
$num = 'Введите номер в поле поиска!';
} elseif (!(strlen($num) == 10) OR !($num[0] == 0)) {
$num .=' - неправильный номер';
}
if(!(strlen($num) == 10) OR !($num[0] == 0)) {
return View::make('numbers.search')->with('num', $num);
} else {
$number = Number::where('number', '=', $num)->first();
$comment = Comment::where('number', '=', $num)->get();
$lun = $this->lun($num);
return View::make('numbers.index')
->with('num', $num)
->with('number', $number)
->with('comment', $comment)
->with('lun', $lun);
}
}
}
public function addNumber() {
$number = Number::firstOrNew(['number' => $_POST['number']]);
if($_POST['ktoeto'] == 'hoz') $number->hoz++;
if($_POST['ktoeto'] == 'brok') $number->brok++;
if($_POST['ktoeto'] == 'klien') $number->klien++;
if($_POST['ktoeto'] == 'mosh') $number->mosh++;
if(!($_POST['comment'] == ''))
{
$comment = new Comment();
$comment->text = $_POST['comment'];
$comment->number = $_POST['number'];
$comment->user_id = 1;
if($comment->save()){
$flash['comment'] = 'Ваш комментарий по номеру '.$_POST['number'].' сохранен';
}
}
if($number->save()){
$flash['number'] = 'Ваше мнение по номеру '.$_POST['number'].' сохранено';
}
return View::make('numbers.search')->with('flash', $flash);
}
}